Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / Javascripts / Productivaty

Address Auto-Fill Ckeck Box

Published by: Alexander McLean III


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>


Next Javascripts Page:
1  2  3  4  [5]  6  7  8  9  10  11  12 





Hosting by iPowerWeb.com - 50 Gb for $7.95