function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
subrat_raysubrat_ray 

auto-populate field values in a object

Hi All,

 

I have two fields of currency type.

Requirement is, when I enter any value in the first field, then it should automatically be

populated in the second as the default value.

If I change the value in the second field, it should hold the latest

value otherwise the default value (same as first).

 

Thanks,

Subrat

 

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

Use Javascript on VF page:

<script type="text/javascript">
function Copyfirstfield()
{
document.getElementById("{!$Component.theFormID.thePageBlockID.secondfieldID}").value = document.getElementById({!$Component.theFormID.thePageBlockID.firstfieldID}").value;
}

    

 

<apex:pageBlockSectionItem id="firstfielditem">
     <apex:outputLabel value="field1"/>
     <apex:inputField value="{!Contacts.firstfield}" id="firstfieldID" onChange="Copyfirstfield();"/>                    
</apex:pageBlockSectionItem>

 

subrat_raysubrat_ray

Thanks Shiva,

 

I am not getting this works.

Below is code. Please have look. Checked with onblur() also.

 

<apex:page standardController="contact">

<script type="text/javascript">
function copyfirstfield()
{
document.getElementById("{!$Component.test.blk.secondfielditem.secondfieldID}").value = document.getElementById("{!$Component.test.blk.firstfielditem.firstfieldID}").value;
}
</script>


<apex:form id="test">
<apex:pageBlock id="blk">
<apex:pageBlockSection >
<apex:pageBlockSectionItem id="firstfielditem">
     <apex:outputLabel value="field1" />
<apex:inputField value="{!Contact.first__c}" id="firstfieldID" onChange="copyfirstfield();"  />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="secondfielditem">
     <apex:outputlabel value="field2" />
<apex:inputField value="{!Contact.second__c}" id="secondfieldID" />                   
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

</apex:page>

 

 

Thanks,

Subrat

 

Shiva Ramesh @ xcdhrShiva Ramesh @ xcdhr

for onChange try this --->onkeyup="Copyfirstfield();"

give pageblock section id. that's missing