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.
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.
I take it the forms are exactly the same? If so, give both forms a name (shipform and billform) and use:
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.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();">
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!
is there a way to do it if the fields are all in one form?
Oh, I see: missed that. Right.
That should work. I haven't tested it yet.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();">
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