I have a radio button called “SameAsMailAddress” on my form with one value assigned to it which is “Same as Mailing Address” and, if selected, copies the value of the mailing address fields values to the delivery address fields. Whenever I click on the radio button nothing happens. The code I copied from another database worked fine before - is there something I am missing? This is the code I have for in the onChange event of the radio button:
var f = document.forms[0];
if (f.SameAsMailAddress.options[f.SameAsMailAddress.selectedIndex].text == “Same as Mailing Address”) {
f.DelCustomerAddress(0) == f.MailCustomerAddress(0);
f.DelCustomerCity(0) == f.MailCustomerCity(0);
f.DelCustomerState(0) == f.MailCustomerState(0);
f.DelCustomerCountry(0) == f.MailCustomerCountry(0);
}
Any help would be much appreciated,
Dan
Subject: onChange JS code not working
You need to get rid of the (0) when referencing your fields and use the assignment operator = instead of the comparison operator ==
e.g. f.DelCustomerAddress.value = f.MailCustomerAddress.value;
Subject: RE: onChange JS code not working
Hi Matt,thanks for the help. However it still does not do what it is ment to do (assign values in the “Mail…” text fields to the “Del…” text fields). Any thoughts on how to make this work?
var f = document.forms[0];
if (f.SameAsMailAddress.options[f.SameAsMailAddress.selectedIndex].text == “Same as Mailing Address”) {
f.DelCustomerAddress.value = f.MailCustomerAddress.value ;
f.DelCustomerCity.value = f.MailCustomerCity.value ;
f.DelCustomerState.value = f.MailCustomerState.value ;
f.DelCustomerCountry.value = f.MailCustomerCountry.value ;
}
Thanks,
Dan
Subject: RE: onChange JS code not working
Missed it earlier but selectedIndex is for use with select boxes not radio buttons.
You need to loop through the radio button to see which has been selected and then check whether the one that has matches your value.
for (i = 0; i < f.SameAsMailAddress.length; i++) {
if (f.SameAsMailAddress[i].checked && f.SameAsMailAddress[i].value == “Same as Mailing Address”) {
f.DelCustomerAddress.value = f.MailCustomerAddress.value;
//etc…
}
}