View Full Version : ASP Form Fill-in
fireplug41
09-20-2005, 03:39 AM
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:
<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.
fireplug41
09-21-2005, 04:15 AM
is there a way to do it if the fields are all in one form?
Oh, I see: missed that. Right.
<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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.