New Blog Format | Hosted on ServerDisk | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Scripts (2,2351) Podcast (video & audio)
 




Home / Javascripts / Productivaty

Address Auto-Fill Ckeck Box

Published by: Alexander McLean III
Javascript code that automatically fills in the address in all places needed on the page after just once entering it and selecting the check box.



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>

    Comments

  1. off1
    April 13, 2009 10:19

    You wrote productivaty ;)
  2. Andrew
    09.04.2008

    The sample source code has a slight error. Copy from the source code of the example page instead and it'll work fine!

    to_el = f['bill' fld_name[i ]]; // on this page

    to_el = f['bill' + fld_name[i++]]; // on working example page

  3. Andrew
    09.04.2008

    The sample source code has a slight error. Copy from the source code of the example page instead and it'll work fine!

    to_el = f['bill' fld_name[i ]]; // on this page

    to_el = f['bill' + fld_name[i++]]; // on working example page

  4. jhankar
    09.08.2004

    hi;
    i am facing aproblem when the fills the form by using googles auto fill feature.in my form i have a country drop down and based on that i am showing states.it's not working when the user comes from autofill is there any solution.plz let me know.
    "jhankar"(j_rayjit@hotmail.com)

Leave a Comment



Related Articles for Javascripts Productivaty:
Articale Address Auto-Fill Ckeck Box
Javascript code that automatically fills in the address in all places needed on the page after just once entering it and selecting the check box.
Articale Popup Chromeless Window
An easy to use Javascript Popup Chromeless Window.
Articale overLIB
overLIB is a JavaScript library created to enhance websites with small popup information boxes (tooltips) to help visitors around your website.
Articale Center Popup Window
Center a popup in the window
Articale List of Top Web Hosting sites with
UNLIMITED DISK SPACE





Hosting - List of top Web Hosting Services with FTP and Unlimited Disk Space