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
Del_SantosDel_Santos 

How to copy inputfield value to another inputfield by checkbox?

Hi,

 

Is it possible to copy the value inputed by the user from inputfield A to inputfield B dynamically by just ticking a checkbox.?

 

Thanks,

Del

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Del_SantosDel_Santos

awww. i figured out the solution! i dont know if all is proper but it works!. :)

 

 

<br></br>
<script language="Javascript">
function FillBilling(f) {
var Cb= document.getElementById('cb');
var Ia= document.getElementById('ia');
var Ba= document.getElementById('ba');

  if(f.cb.checked == true) {
    f.ba.value = f.ia.value;
    f.ba.disabled = true;
  }
  else
  {
  f.ba.disabled = false;
  f.ba.value = "";
  }
}
</script>
<b>Mailing Address</b>
<br></br>
Name:<input type="text" name="{!Lead.Installation_House__c}" id="ia"/>
<br></br><input type="checkbox" name="{!Lead.Cpy_from_Installation_Address__c}" onclick="FillBilling(this.form)" id="cb"/>
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<P></P>
<b>Billing Address</b>
<br></br>
Name:<input type="text" name="{!Lead.Billing_House__c}" id="ba"/>

All Answers

iBr0theriBr0ther

Why not?

Use JS to complete it.

Del_SantosDel_Santos

Thanks PoorMan.

 

I created  a JS script, and it is working in my force.com site, however, not when i substitute my actual fields in the code. Can someone help me on how to do this. here's my code.

 

<script language="Javascript">
function FillBilling(f) {
  if(f.copyYesNo.checked == true) {
    f.billingAddress.value = f.installationAddress.value;
    f.billingAddress.disabled = true;
  }
  else
  {
  f.billingAddress.disabled = false;
  f.billingAddress.value = "";
  }
}
</script>
<b>Mailing Address</b>
<br></br>
Name:<input type="text" name="installationAddress" />
<br></br><input type="checkbox" name="copyYesNo" onclick="FillBilling(this.form)"/>
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<P></P>
<b>Billing Address</b>
<br></br>
Name:<input type="text" name="billingAddress" />

 

 

..and here's my actual salesforce fields.


{!Lead.copyYesNo__c} = copyYesNo
{!Lead.installationAddress} = installationAddress
{!Lead.billingAddress} = billingAddress

 

Thanks in advance!

 

Del

Del_SantosDel_Santos

awww. i figured out the solution! i dont know if all is proper but it works!. :)

 

 

<br></br>
<script language="Javascript">
function FillBilling(f) {
var Cb= document.getElementById('cb');
var Ia= document.getElementById('ia');
var Ba= document.getElementById('ba');

  if(f.cb.checked == true) {
    f.ba.value = f.ia.value;
    f.ba.disabled = true;
  }
  else
  {
  f.ba.disabled = false;
  f.ba.value = "";
  }
}
</script>
<b>Mailing Address</b>
<br></br>
Name:<input type="text" name="{!Lead.Installation_House__c}" id="ia"/>
<br></br><input type="checkbox" name="{!Lead.Cpy_from_Installation_Address__c}" onclick="FillBilling(this.form)" id="cb"/>
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<P></P>
<b>Billing Address</b>
<br></br>
Name:<input type="text" name="{!Lead.Billing_House__c}" id="ba"/>

This was selected as the best answer