Click to See Complete Forum and Search --> : Form element array problem. Please Help!!!


unknown_striker
02-23-2003, 03:14 AM
Hi all,

I am having a problem with accessing values in a form element array.

Basically, for example, I have 20 hidden fields and I want to swap 2 values of 2 selected fields. When the swap function is executed I assign the value of one of the fields to a temporary variable, eg.

tempnum = eval("document.formname.elementname[" + swapnum1 + "].value");

But when I run the code, I get an error and in the error message it says:

'document.formname.elementname.1' is not an object

Notice that instead of being document.formname.elementname[1].value it is actually changed to document.formname.elementname.1, but I don't know why. Can anyone explain to me where I am going wrong?

Thanks in advance,
Chris

Timbuck2
02-23-2003, 04:19 AM
Not sure, but you have too many literals in that code I think.

So you may want to break it up.

var mForm = document.forms(nameOfForm)
var el = mForm.item(nameOfElement)
alert (el.value)

or eval it in pieces

Dan Drillich
02-23-2003, 08:36 AM
The following might help -


<SCRIPT LANGUAGE="javascript">
<!--
function swap() {
var tempnum = document.declaration.a.value;

document.declaration.a.value = document.declaration.b.value;
document.declaration.b.value = tempnum;

//alert(tempnum);


}

//-->
</SCRIPT>


<form name="declaration" action="applications.html" onsubmit="swap();return false;">

<center>
<input type="text" name="a" value="1" />a
<input type="text" name="b" value="2" />b

</center>

<br>
<br>

<center>
<input type="submit" value="Begin" name="applications" align="right" >
</center>

</form>