In
an order form, it is common for the shipping and billing addresses to
be the same, so it is helpful to the user if the billing address defaults
to what they've entered for the shipping address. Other useful features
include having the focus automatically switch to a particular field
upon a user selection.
Add the copy_shipping function to the script in ordertxt.htm
as follows:
function copy_shipping() {
if (document.order.billcb.checked) {
document
.order.bname.value=document.order.sname.value;
document.order.bstreet.value=document.order.sstreet.value;
document.order.bcity.value=document.order.scity.value;
document.order.bstate.selectedIndex=document.order.sstate.selectedIndex;
document.order.bzip.value=document.order.szip.value;
}
}
Add the onclick event handler to the billcb checkbox:
onclick="copy_shipping()"
Save and test in browser.
Add the use_credit function so the focus switches to the credit card
name field upon user selection:
function use_credit() {
if (document.order.creditcb.checked) document.order.cname.focus();
}
Add the onclick event handler to the creditcb field:
onclick="use_credit()"
Save and test the form.
Troubleshooting
Tips
In the event you get an error, IE helps you troubleshoot the error.
As you test your scripts, look in the bottom left corner of the status
bar in IE for the error icon:
Double-click the icon for information about where the browser encountered
the error.