You need to sign in to do that
Don't have an account?
Ramon Pereira
Java Script in VisualForce
Hi,
I would like to copy the value from one field to another automatically.
I made the following code, but it does not run.
Someone must help me?
<apex:page standardController="Opportunity" id="page1" > <apex:sectionHeader title="Test"/> <apex:messages /> <apex:form id="form1"> <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!save}" title="Salvar" value="Salve" /> <apex:commandButton action="{!cancel}" title="Cancelar" value="Cancel" /> </apex:pageBlockButtons> <apex:panelGrid columns="2"> <apex:outputLabel >Client:</apex:outputLabel> <apex:inputField value="{!Opportunity.AccountId}" required="true" id="campo2" /> <apex:outputLabel > Name: </apex:outputLabel> <apex:inputField value="{!Opportunity.name}" id="campo1" onblur="copyT()" /> <apex:outputLabel > Stage: </apex:outputLabel> <apex:inputField value="{!Opportunity.StageName}" /> <apex:outputLabel > Date: </apex:outputLabel> <apex:inputField value="{!Opportunity.CloseDate}" /> </apex:panelGrid> </apex:pageBlock> </apex:form> <script type="text/javascript"> function copyT(){ valor = document.getElementById('{!$Component.campo1}').value; document.getElementById('{!$Component.campo2}').value = valor; } </script> </apex:page>
You need to chain the ids. Below is a simplified example:
All Answers
Hello,
First of all check the error console to see if you don't have errors. I highly recommend using Firebug on Firefox(an addon)... Also check Development Mode and Show View State on the Setup > Personal Information page.
Second, I think you need to rerender the page to see the changes.
Add an actionsupport to the input element.
Have a great day!
Adrian
Hi,
Actually I need a way to capture the id generated by the sales force.
I used the sixtaxe ('{!} $ Component.campo1') to capture the id of the component, but to analyze the generated HTML it is not generating the component ID.
My need is to find the component ID.
thank you
You need to chain the ids. Below is a simplified example: