How I can use the id in javascript

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

    #1

    How I can use the id in javascript

    Hi
    How I can use the id in javascript to get an information or to populate the
    text control
    exemple <input type="text" id=1 name="name" value=""/>

    I need help please.



  • David Dorward

    #2
    Re: How I can use the id in javascript

    hak wrote:[color=blue]
    > How I can use the id in javascript to get an information or to populate
    > the text control
    > exemple <input type="text" id=1 name="name" value=""/>[/color]

    First you use valid (X)HTML.

    If you are using HTML, you shouldn't have that "/" in there.
    In you are using XHTML then you must quote all your attribute values.
    Either way, id="1" isn't valid, because ids must begin with a letter.

    Then you use DOM.

    document.getEle mentById('value-of-id-attribute')

    will return a reference to the element. Then you can access whatever
    properties of it you like, such as the value.

    --
    David Dorward <http://dorward.me.uk/>

    Comment

    • Jeff North

      #3
      Re: How I can use the id in javascript

      On Wed, 3 Mar 2004 16:04:28 -0500, in comp.lang.javas cript "hak"
      <s_abdelhakim@h otmail.com> wrote:
      [color=blue]
      >| Hi
      >| How I can use the id in javascript to get an information or to populate the
      >| text control
      >| exemple <input type="text" id=1 name="name" value=""/>
      >|
      >| I need help please.[/color]

      <input type="text" id="name1" name="name" value="" />

      //--- get value
      var id = getElementById( "name1").va lue;

      //--- set value
      getElementById( "name1").va lue = "1234";
      ---------------------------------------------------------------
      jnorth@yourpant sbigpond.net.au : Remove your pants to reply
      ---------------------------------------------------------------

      Comment

      • Jeff North

        #4
        Re: How I can use the id in javascript

        Fixed missing document. instruction.

        On Thu, 04 Mar 2004 04:42:01 GMT, in comp.lang.javas cript Jeff North
        <jnorth@yourpan tsbigpond.net.a u> wrote:
        [color=blue]
        >| On Wed, 3 Mar 2004 16:04:28 -0500, in comp.lang.javas cript "hak"
        >| <s_abdelhakim@h otmail.com> wrote:
        >|
        >| >| Hi
        >| >| How I can use the id in javascript to get an information or to populate the
        >| >| text control
        >| >| exemple <input type="text" id=1 name="name" value=""/>
        >| >|
        >| >| I need help please.
        >|
        >| <input type="text" id="name1" name="name" value="" />
        >|
        >| //--- get value[/color]
        var id = document.getEle mentById("name1 ").value;[color=blue]
        >|
        >| //--- set value[/color]
        document.getEle mentById("name1 ").value = "1234";[color=blue]
        >| ---------------------------------------------------------------
        >| jnorth@yourpant sbigpond.net.au : Remove your pants to reply
        >| ---------------------------------------------------------------[/color]

        ---------------------------------------------------------------
        jnorth@yourpant sbigpond.net.au : Remove your pants to reply
        ---------------------------------------------------------------

        Comment

        Working...