Results 1 to 4 of 4

Thread: ASP Form Fill-in

  1. #1
    Join Date
    Aug 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ASP Form Fill-in

    I have a form that has 2 sections. Shipping and Billing information. I have a checkbox for same information. I am trying to figure out how to autofill the Billing fields when they fill in the Shipping information.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I take it the forms are exactly the same? If so, give both forms a name (shipform and billform) and use:
    Code:
    <script type="text/javascript">
    function cloneForm() {
      var s = document.forms['shipform'].elements,
        b = document.forms['billform'].elements;
      for(var i=0;i<s.length;i++) {
        b[i].value = s[i].value;
      }
    }
    </script>
    <input type="checkbox" onclick="if(this.checked) cloneForm(); else document.getElementById('billform').reset();">
    Note, however, that if the billing form has a different number of elements to the shipping form, or they're in different places, this will not work.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    is there a way to do it if the fields are all in one form?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Oh, I see: missed that. Right.
    Code:
    <script type="text/javascript">
    function cloneForm() {
      var s = document.forms['shipform'].elements,
        billingFormOffset = 10;  // Number of elements in the "billing" part of the form
      for(var i=0;i<billingFormOffset;i++) {
        s[i + billingFormOffset].value = s[i].value;
      }
    }
    </script>
    <input type="checkbox" onclick="if(this.checked) cloneForm(); else document.getElementById('billform').reset();">
    That should work. I haven't tested it yet.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •