469,642 Members | 1,244 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,642 developers. It's quick & easy.

input name=integer

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
Feb 7 '07 #1
8 3919
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;
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 7 '07 #2
On 7 Feb, 17:05, M <Mwrote:
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

Feb 7 '07 #3
M wrote:
<input name='5' type='text'/>
But document.getElementById("myform").elements["5"].value
does not give the right result,
document.getElementById("myform").elements.namedIt em("5").value
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 7 '07 #4
M wrote:
Hello,

Here is my input field :

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

I can't change it. I must use an integer for the name.
Yes you can
>
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).
function getValueOfNamedInput(V,form){
f=form.length
while(f--){if(form[f].name==V)return form[f].value;}
}

Mick
Feb 7 '07 #5
mi**********@lineone.net wrote:
<input type="text" name="5" value="test" id="5">
Not valid, since id's may not begin with a number.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Feb 7 '07 #6
On 7 Feb, 19:15, "Matt Kruse" <newsgro...@mattkruse.comwrote:
mike_solo...@lineone.net wrote:
<input type="text" name="5" value="test" id="5">

Not valid, since id's may not begin with a number.

--
Matt Krusehttp://www.JavascriptToolbox.comhttp://www.AjaxToolbox.com
Well I tested it before I posted and it worked under IE :)

Feb 7 '07 #7
M <Mwrote:
>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.

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
Feb 7 '07 #8
mi**********@lineone.net said the following on 2/7/2007 2:27 PM:
On 7 Feb, 19:15, "Matt Kruse" <newsgro...@mattkruse.comwrote:
>mike_solo...@lineone.net wrote:
>><input type="text" name="5" value="test" id="5">
Not valid, since id's may not begin with a number.

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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 8 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

38 posts views Thread by Keith | last post: by
11 posts views Thread by sang | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.