469,898 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How I can use the id in javascript

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

Jul 20 '05 #1
3 6838
hak wrote:
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=""/>


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.getElementById('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/>
Jul 20 '05 #2
On Wed, 3 Mar 2004 16:04:28 -0500, in comp.lang.javascript "hak"
<s_**********@hotmail.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
var id = getElementById("name1").value;

//--- set value
getElementById("name1").value = "1234";
---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 20 '05 #3
Fixed missing document. instruction.

On Thu, 04 Mar 2004 04:42:01 GMT, in comp.lang.javascript Jeff North
<jn****@yourpantsbigpond.net.au> wrote:
| On Wed, 3 Mar 2004 16:04:28 -0500, in comp.lang.javascript "hak"
| <s_**********@hotmail.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 var id = document.getElementById("name1").value;|
| //--- set value document.getElementById("name1").value = "1234";| ---------------------------------------------------------------
| jn****@yourpantsbigpond.net.au : Remove your pants to reply
| ---------------------------------------------------------------


---------------------------------------------------------------
jn****@yourpantsbigpond.net.au : Remove your pants to reply
---------------------------------------------------------------
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.