[Javascript] how to refer to (x)html elements
Peter Brunone
peter at brunone.com
Wed Nov 12 12:17:29 CST 2003
Before anyone takes me down on my first point, let me add the
caveat that it's perfectly all right to name *some* elements the same,
if you want them to act as an array (e.g. radio buttons).
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Peter Brunone
Hi Tim,
First of all, you should never give any of your elements the
same name or id attribute... *especially* if you want to use the second
approach.
To refer to an element by id, you just use
document.getElementById("elementID") and instantly you have a reference
to that object, whatever it is. There's no need to go through the form
object in the old DOM.
Cheers,
Peter Brunone
-----Original Message-----
From: javascript-bounces at LaTech.edu
[mailto:javascript-bounces at LaTech.edu] On Behalf Of Tim Burgan
hello,
as i've been trying to learn javascript - i'm a little stuck.. again
I don't know how to explain this, but instead of:
document.formName.inputName.value
(eg. <form name="example"> <input name="example">)
i want to use:
document.formId.inputId.value
(eg. <form id="example"> <input id="example" />)
the reason being, that to use the first example I must use
non-standards-compliant xhtml code in my documents.
So is there a way that JavaScript can use xhtml tag's ID elements rather
than the depreciated NAME element?
Thanks
Tim Burgan
More information about the Javascript
mailing list