When you create a web form for web page of any website, users need to fill the details in the fields like name, address, phone number etc. sometimes when filling the details there may be some fields which you need to fill twice. Instead of having your users to fill out those form field twice, you can copy data of those fields from one to another by using javascript.
Here is how to use javascript to copy data. Following example shows when clicking on checkbox field the data entered will automatically copy to the other fields.
Example:
HTML:
<b>Mailing Address</b>
<br><br>
<form>
Name:
<input type="text" name="shippingname">
<br>
City:
<input type="text" name="shippingcity">
<br>
<input type="checkbox" name="billingtoo" onclick="FillBilling(this.form)">
<em>Check this box if Billing Address and Mailing Address are the same.</em>
<P>
<b>Billing Address</b>
<br><br>
Name:
<input type="text" name="billingname">
<br>
City:
<input type="text" name="billingcity">
</form>
Javascript:
function FillBilling(f) {
if(f.billingtoo.checked == true) {
f.billingname.value = f.shippingname.value;
f.billingcity.value = f.shippingcity.value;
}
}
Here is the demo.
0 Comment(s)