View Full Version : Automatically Populating One Field With Another?

03-18-2005, 03:04 PM
Hey Guys,

Question - I've got a form with these 2 fields: "for" and "ship to". When the user enters data for the "for" field (something like this):

Name of Company
Address of Company
City, State, Zip

After they tab onto the next field, how can I get that data to automatically populate in the "ship to" box? Currently both of these fields are textareas.

Thanks much.

03-18-2005, 04:23 PM
Something like this?:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<textarea name="t1" cols="30" rows="3" onkeyup="this.form.elements['t2'].value=this.value"></textarea>
<textarea name="t2" cols="30" rows="3"></textarea>

03-18-2005, 04:33 PM
Nice .. . I just came up with:

// copies forField into shipTo field
function ForToShipTo() {
var val3 = document.myForm.forField.value;
document.myForm.shipTo.value = val3;

<textarea name="forField" class="textbox" rows="5" cols="60" onblur="ForToShipTo()"></textarea>
<textarea name="shipTo" class="textbox" rows="5" cols="70"></textarea>

Same thing it looks like, only yours does it on the fly.

Thanks for the help.

03-18-2005, 05:08 PM
I often try to avoid direct (name,id) referenceing by using either this self reference (with variants this.form, this.value, this.parentNode, this.getElementsByTagName(tagname)[index] ... and so on). It makes the code more useful and dynamic...

03-18-2005, 05:14 PM
True .. that would be helpful with my next issue.


Any ideas? :)