Click to See Complete Forum and Search --> : Accessing form objects by dynamic object creation, Please HELP


kari
05-08-2003, 04:05 PM
Hi,

I need help in solving this urgently, please help...

I need to access the form objects name/value pair
(<INPUT type=hidden name=xxxi value=yyy>) from Javascript dynamically

<input type=hidden name=s2 value=2>
<input type=hidden name=s3 value=3>
<input type=hidden name=s4 value=4>
<input type=hidden name=s5 value=5>
<input type=hidden name=s6 value=6>
<input type=hidden name=s7 value=7>
<input type=hidden name=s8 value=8>
<input type=hidden name=sn value=8> where n is a variable.

....
Like this there will be n of name/values.
So in Javascript, I know n, so how do I access this particular name
with in javascript.


switch (num) {
case "1":
srcPortNum = window.document.forms[1].s2portNum1.value;
break;
case "2":
srcPortNum = window.document.forms[1].s2portNum2.value;
break;
}

I don't want to do this, as num may be huge number. Is there any way that
I can just simply say
srcPortNum = window.document.forms[1].xxxxx.value;
where xxxxx is a number.



Please help me ..

khalidali63
05-08-2003, 04:15 PM
yes you can do something like this.
Consider X is a number relative to a specific field

var field =
eval('document.formName.s'+x);
//now you can access any attribute that field may have
aler(field.name)

kari
05-08-2003, 04:17 PM
Hi,

I need help in solving this urgently, please help...

I need to access the form objects name/value pair
(<INPUT type=hidden name=xxxi value=yyy>) from Javascript dynamically

<input type=hidden name=s2 value=2>
<input type=hidden name=s3 value=3>
<input type=hidden name=s4 value=4>
<input type=hidden name=s5 value=5>
<input type=hidden name=s6 value=6>
<input type=hidden name=s7 value=7>
<input type=hidden name=s8 value=8>
<input type=hidden name=sn value=8> where n is a variable.

....
Like this there will be n of name/values.
So in Javascript, I know n, so how do I access this particular name
with in javascript.


switch (num) {
case "1":
srcPortNum = window.document.forms[1].s2portNum1.value;
break;
case "2":
srcPortNum = window.document.forms[1].s2portNum2.value;
break;
}

I don't want to do this, as num may be huge number. Is there any way that
I can just simply say
srcPortNum = window.document.forms[1].xxxxx.value;
where xxxxx is a number.



Please help me ..

khalidali63
05-08-2003, 04:19 PM
your first post was enough.:D
There was no need for second thread for the same topic....
You know you can delete this one..:-)

kari
05-08-2003, 04:28 PM
thanks a ton Khalid, it really works.:)

khalidali63
05-08-2003, 04:36 PM
you are most welcome..:D