[thelist] Identifying HTML Elements with javascript

Christian Heilmann codepo8 at gmail.com
Fri Jul 7 11:35:20 CDT 2006


> Hi all,
>
> I'm working on a javascript form validation script and I am trying to
> cycle through an array of html objects (in this case they are form
> elements, inputs, selects, etc.) and I want to know what the best way
> to get javascript to figure out exactly what type of object it is
> dealing with so I can execute a different function to validate a text
> field, select, radio, etc.
>
> Currently I've got it to work (for checking if its a select object)
> with the following if statement
>
> if (elem == "[object HTMLSelectElement]") {
>
> }

Loop through the DOM1 elements collection of the form and check for
nodeName for each of them.

Be aware that there is select-one and select-multiple.

Or use getElementById and type.

http://www.beginningjavascript.com/Chapter9/topList.js


-- 
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/



More information about the thelist mailing list