Javascript help - same as customer info script issue
Hi,
I have a form feature that will copy the already inputed form given by the visitor (eg: name, address, zip) and when a check box is checked it will put that form info again into the pickup address, and then another check box that will put the same info into the delivery address area.
The issue is that if the visitor does not enter the info in the first step area that the script grabs from, it will remove the form info when the visitor does go to the first step. And if the visitor decides to change something in either field it will remove everything. Any ideas? Here is the code :
Code:
<script type="text/javascript" language="javascript">
function set_billing(box)
{
var f = box.form, b_which = box.checked, from_el, to_el, i = 0;
var fld_name = new Array('customerInfoBusiness' , 'customerInfoLastName' , 'customerInfoFirstName' ,'customerInfoAddress' ,'customerInfoCity' ,'customerInfoState' ,'customerInfoZip' ,'customerInfoPhones' , '');
while (from_el = f[fld_name[i]])
{
to_el = f['p' + fld_name[i++]];
to_el.value = b_which ? from_el.value : '';
if (to_el.readOnly != null)
to_el.readOnly = b_which ? true : false;
else to_el.onfocus = b_which ? function() {this.blur();
}
: null;
}
}
</script>
<script type="text/javascript" language="javascript">
function set_deliver(box)
{
var f = box.form, b_which = box.checked, from_el, to_el, i = 0;
var fld_name = new Array('customerInfoBusiness' , 'customerInfoLastName' , 'customerInfoFirstName' ,'customerInfoAddress' ,'customerInfoCity' ,'customerInfoState' ,'customerInfoZip' ,'customerInfoPhones');
while (from_el = f[fld_name[i]])
{
to_el = f['d' + fld_name[i++]];
to_el.value = b_which ? from_el.value : '';
if (to_el.readOnly != null)
to_el.readOnly = b_which ? true : false;
else to_el.onfocus = b_which ? function() {this.blur();
}
: null;
}
}
</script>
that is at the first step. It appears to not have that glitch now and it still copies the info when the check box is checked. BUT it wont automatically change the copied information when the visitor changes a field in step 1.