Click to See Complete Forum and Search --> : Property and Object!


said_fox
08-15-2003, 03:54 PM
A page have two forms. On certain event I want to transfer the value of one form's elements to
the other's elements.
Consider the following code:

<form name="form1">
<input type="text" name="txt1" onblur="trans(this)">
<input type="text" name="txt1" onblur="trans(this)">
</form>

<form name="form2">
<input type="text" name="txt1">
<input type="text" name="txt2">
</form>

I had written the following code for the trans() function:

function trans(arg){
val = arg.value;
nam = arg.name;
document.form2.nam.value = val;
}

You may noticed that the elements names are identical. The nam Variable holds the corresponding
element's name of form1.

An error message is obtained from the above code it tolds that "document.form2.nam is null or not an object"!
So How can I use the nam variable to supply dynamically the form2's element name?
as coded in "document.form2.nam.value = val;"

Is there any help?

Charles
08-15-2003, 04:00 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
</head>
<body>
<form name="form1">
<div>
<input type="text" name="text1" onchange="document.forms.form2[this.name].value = this.value">
<input type="text" name="text2" onchange="document.forms.form2[this.name].value = this.value">
</div>
</form>

<form name="form2">
<div>
<input type="text" name="text1">
<input type="text" name="text2">
</div>
</form>
</body>
</html>

said_fox
08-15-2003, 05:57 PM
Thank You It's so useful idea. However, it does not run under Mozilla.
My Mozilla Version is 1.3. Is there any way to make it work under Mozilla too?:)