Introduction:
I ran accross this code when working on a registration
product site. The goal is to save the user's time by not
having them fill in the same address over and over, if the
address for there billing is the same as the mailing address.
You can view a working form by clicking
here.
Source 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('city' , 'state');
while (from_el = f[fld_name[i]])
{
to_el = f['bill' 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>
</head>
<body>
<form>
<table>
<tr>
<td align="right">
<strong>Mailing Address</strong><br>
City: <input name="city" type="text"
id="city" onchange="set_billing(billingaddrsame)"><br>
State: <input name="state" type="text"
id="state" onchange="set_billing(billingaddrsame)"><br>
<strong>Billing Address</strong><br>
( same as above)
<input type="checkbox" name="billingaddrsame"
onclick="set_billing(this)"><br>
City: <input name="billcity" type="text"
id="billcity"><br>
State: <input name="billstate" type="text"
id="billstate"><br>
</td>
</tr>
</table>
</form>
NewSourceMedia is providing links to these listings as
a courtesy, and makes no representations regarding the content or
any information related thereto. Any questions, complaints or claims
regarding the downloaded content or details must be directed to the appropriate
publisher. We do not encourage or condone the use of any
software in violation of applicable laws.