PDA

View Full Version : script to copy info from one form to another by clicking a button


bostick
09-16-2002, 09:09 PM
Hi,
I'm new to javascript, so I know this is probably a remedial question for most...but I have searched for some time though with no luck so I decided to post here. Anyway, I need a button (and the associated function) that when clicked, will copy the information from one form to another. Example, if the shipping address information for an order is the same as the billing address information, I would like to arrange it so that a button is clicked allowing the information to transfer over, but if the information is different, the person can simply enter in the different address. Thank you very much-again my apologies for such a mundane question!

Joe

Roy Sinclair
09-16-2002, 09:40 PM
Why not handle this on the server when the form is posted?

A short note on the page telling the user that the primary billing address will be used as the shipping address if the shipping address is left blank is all that should really be needed.

beetle
09-16-2002, 09:47 PM
I agree with Roy, but if a solution you must have, look no further.
<HTML>
<HEAD>
<TITLE>Fill In test</TITLE>

<script>
var sFields = new Array('Shipping_Name','Shipping_Address','Shipping_State');
var bFields = new Array('Billing_Name','Billing_Address','Billing_State');

function fillIn(f,bool) {
if (bool) {
for (var i=0; i<sFields.length; i++) {
f.elements[sFields[i]].value = f.elements[bFields[i]].value;
f.elements[sFields[i]].disabled = true;
}
}
else {
for (i=0; i<sFields.length; i++) {
f.elements[sFields[i]].value = "";
f.elements[sFields[i]].disabled = false;
}
}
}
</script>

<style>
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #FFFFFF; color: #000000; }
</style>
</HEAD>

<BODY>
<form>
<b>Billing:</b><br>
Name<input type="text" name="Billing_Name"><br>
Address<input type="text" name="Billing_Address"><br>
State<input type="text" name="Billing_State"><br>
<br>
Shipping same as biling?<input type="checkbox" value="Same_as_billing" onClick="fillIn(this.form, this.checked)"><br>
<br>
<b>Shipping:</b><br>
Name<input type="text" name="Shipping_Name"><br>
Address<input type="text" name="Shipping_Address"><br>
State<input type="text" name="Shipping_State"><br>
</form>
</BODY>
</HTML>