How to copy information from other fields

In this article we will provide a quick implementation for the following type of scenario: copying information like first name, last name and address from one form section - Billing Details, to another - Shipping Details.

The article consists in a step-by-step guide to implementing this, but you can also download the sample form by clicking on the button to the right.



Form Fields


Add, to your form, the following textboxes:


Internal Name Caption
billingfirstname First Name
billinglastname Last Name
billingaddress Address
shippingfirstname First Name
shippinglastname Last Name
shippingaddress Address

Also, add a radio group containing the following items:


  • Same as Billing Information
  • Different Shipping Information

In the radio group's "Attributes" tab, add onclick="copy();" in the "Additional Attributes" field. This will trigger the actual Javascript function that will copy the fields information.


Javascript


To copy the information typed in the billing fields, we will be using the following Javascript code:

<script type="text/javascript">
function copy(){
if (document.getElementById("copy0").checked==true)
  {
    document.getElementById("shippingfirstname").value=document.getElementById("billingfirstname").value;
    document.getElementById("shippinglastname").value=document.getElementById("billinglastname").value;
    document.getElementById("shippingaddress").value=document.getElementById("billingaddress").value;
  }

else if (document.getElementById("copy1").checked==true)
  {
    document.getElementById("shippingfirstname").value="";
    document.getElementById("shippinglastname").value="";
    document.getElementById("shippingaddress").value="";
  }
}
</script>

Copy this code and paste it in Components >> RSForm!Pro >> Manage Forms >> edit your form >> Properties >> CSS and Javascript >> Javascript tab.

The code will verify if the Same as Billing Information radio option is checked and, if it is, will copy the text that the user typed in the billing fields to the shipping fields. If the Different Shipping Information option is checked, the shipping fields will be cleared.


14 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Set up conditionals for groups of fields HOT

Fields are not showing up in the frontend HOT

Calculate user's age using BirthDay field

Display Last Edited Date in Submissions Directory