Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How To Use JavaScript To Copy Text From One Field To Another

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3.53k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: