Scripting checkbox to duplicate field info in form

S

Steve

Hi,

I have created a html form which has duplicate fields to collect Account
name and address etc and Delivery name and address etc.

If the info is the same for delivery as for account - does anyone know how I
can script a checkbox which duplicates the info to save the visitor having to
fill it out twice.

Eg tick this checkbox if delivery details is the same as account details

Any articles on this would be appreciated.

Thanks
 
J

Jon Spivey

Hi Steve,

You could make your form like this
<form>
Billing Address
Name <input type="text" name="a1">
Address <input type="text" name="a2">
Shipping Address
Name <input type="text" name="b1">
Address <input type="text" name="b2">
Shipping Same as Billing <input type="checkbox"
onclick="fillShipping(this.form);">
</form>
<script type="text/javascript">
function fillShipping(f){
f=f.elements;
for(i=0;i<f.length-1;i++){
if(f.name.indexOf('a')==0){f[f.name.replace('a','b')].value=f.value;}
}}
</script>

I've just named the form fields in the billing section as a1, a2 etc and in
the shipping section as b1, b2 etc so you can add as many form fields as you
like and the script will loop through the form and transfer all the values
from billing to shipping

Cheers,
Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top