input name=integer

Discussion in 'Javascript' started by M, Feb 7, 2007.

  1. M

    M Guest

    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
     
    M, Feb 7, 2007
    #1
    1. Advertising

  2. M

    Tim Slattery Guest

    M <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.
    >
    >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

    http://members.cox.net/slatteryt
     
    Tim Slattery, Feb 7, 2007
    #2
    1. Advertising

  3. M

    Evertjan. Guest

    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)
     
    Evertjan., Feb 7, 2007
    #3
  4. M

    Guest

    On 7 Feb, 17:05, M <M> wrote:
    > 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, 2007
    #4
  5. M

    Matt Kruse Guest

    Matt Kruse, Feb 7, 2007
    #5
  6. M

    Guest

    On 7 Feb, 19:15, "Matt Kruse" <> wrote:
    > 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, 2007
    #6
  7. M

    Randy Webb Guest

    said the following on 2/7/2007 2:27 PM:
    > On 7 Feb, 19:15, "Matt Kruse" <> wrote:
    >> 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/
     
    Randy Webb, Feb 7, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,974
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    No Math.min(Integer, Integer)?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    534
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Jul 29, 2003
  3. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    2
    Views:
    518
    Yu SONG
    Oct 15, 2004
  4. Sebastian Stelzer

    How do I add an Integer to another Integer?

    Sebastian Stelzer, Oct 14, 2004, in forum: Java
    Replies:
    6
    Views:
    45,784
    JavaBean2010
    Apr 7, 2010
  5. Ivan S

    Function name and input name property

    Ivan S, Oct 5, 2009, in forum: Javascript
    Replies:
    6
    Views:
    97
    Ivan S
    Oct 6, 2009
Loading...

Share This Page