Accessing form control elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DU

    Accessing form control elements


    Assuming you have a typical form built in this manner:

    <form action="...">
    <p><input id="idInputText " name="nameInput Text" type="text" size="20"></p>
    <p><input id="idCheckbox " name="nameCheck box">optional</p>
    <p><input id="idRadio1" name="nameRadio ">yes<input id="idRadio2"
    name="nameRadio ">no</p>
    <p><select id="idSelect" name="nameSelec t"><option
    value="a">a</option><option value="b">b</option><option
    value="c">c</option></select></p>
    </form>

    then what would be the most efficient way of referencing these form
    control elements? With the name attribute or with the id attribute?

    With
    document.forms[0].nameInputText
    or with
    document.getEle mentById("idInp utText")?
    Same thing with other form control elements. Id or name? Which is the
    most efficient?

    How can you measure this for comparison purposes?

    DU
    --
    Javascript and Browser bugs:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


  • lallous

    #2
    Re: Accessing form control elements

    For compatibility reasons accessing via form.ElementNam e is better.[color=blue]
    > document.forms[0].nameInputText[/color]
    imho, this is better especially if you don't want to do more than form
    element management. (reading/writing value).

    Elias

    "DU" <drunclear@hotR EMOVEmail.com> wrote in message
    news:bgqpkd$u9$ 1@news.eusc.int er.net...[color=blue]
    >
    > Assuming you have a typical form built in this manner:
    >
    > <form action="...">
    > <p><input id="idInputText " name="nameInput Text" type="text" size="20"></p>
    > <p><input id="idCheckbox " name="nameCheck box">optional</p>
    > <p><input id="idRadio1" name="nameRadio ">yes<input id="idRadio2"
    > name="nameRadio ">no</p>
    > <p><select id="idSelect" name="nameSelec t"><option
    > value="a">a</option><option value="b">b</option><option
    > value="c">c</option></select></p>
    > </form>
    >
    > then what would be the most efficient way of referencing these form
    > control elements? With the name attribute or with the id attribute?
    >
    > With
    > document.forms[0].nameInputText
    > or with
    > document.getEle mentById("idInp utText")?
    > Same thing with other form control elements. Id or name? Which is the
    > most efficient?
    >
    > How can you measure this for comparison purposes?
    >
    > DU
    > --
    > Javascript and Browser bugs:
    > http://www10.brinkster.com/doctorunclear/
    > - Resources, help and tips for Netscape 7.x users and Composer
    > - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    > http://www10.brinkster.com/doctorunc...e7Section.html[/color]


    Comment

    Working...