input name=integer

M

M

Hello,

Here is my input field :

<input name='5' type='text'/>

I can't change it. I must use an integer for the name.

I need javascript code to get its value.

But document.getElementById("myform").elements["5"].value
does not give the right result, it gives the value from another field
(the 5th of the list, not the one whose name is 5).

Please help.

Thanx !
M
 
T

Tim Slattery

M said:
Hello,

Here is my input field :

<input name='5' type='text'/>

I can't change it. I must use an integer for the name.

I need javascript code to get its value.

But document.getElementById("myform").elements["5"].value
does not give the right result, it gives the value from another field
(the 5th of the list, not the one whose name is 5).

How about

document.getElementsBy Name("5")[0]

Assuming there's only one item with name="5" in your page.
 
E

Evertjan.

M wrote on 07 feb 2007 in comp.lang.javascript:
Here is my input field :

<input name='5' type='text'/>

I can't change it. I must use an integer for the name.

I need javascript code to get its value.

'need' and 'must', who is the boss overthere?
But document.getElementById("myform").elements["5"].value
does not give the right result, it gives the value from anot

var myF = document.getElementById('myform');
var myT = myF.getElementsByTagName('input');

for (var r=0;r<myT.length;r++)
if (myT[r].name == '5')
var result = myF[r].value;
 
M

mike_solomon

Hello,

Here ismyinput field :

<input name='5' type='text'/>

I can't change it. I must use an integer for the name.

I needjavascriptcode to get its value.

But document.getElementById("myform").elements["5"].value
does not give the right result, it gives the value from another field
(the 5th of the list, not the one whose name is 5).

Please help.

Thanx !
M

Use

<input type="text" name="5" value="test" id="5">

document.getElementById("5").value

to use document.getElementById you must set an id
 
R

Randy Webb

(e-mail address removed) said the following on 2/7/2007 2:27 PM:
Well I tested it before I posted and it worked under IE :)

Being able to say "it worked under IE" doesn't mean a whole lot though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,169
Latest member
ArturoOlne
Top