[thelist] Identifying HTML Elements with javascript

Christian Heilmann codepo8 at gmail.com
Fri Jul 7 13:53:42 CDT 2006


Actually, no. As nodeName returns INPUT for both text and checkboxes
and you need to validate them differently in JavaScript (server side
you can check for the value sent). Therefore type is your friend.

Och, I spent about an hour writing examples how to validate different
form elements for the Data Validation Techniques chapter
(http://www.beginningjavascript.com/Chapter9/index.html). It can get
annoying :-)


On 7/7/06, Ben Glassman <bglassman at gmail.com> wrote:
> Great. nodeName is exactly what I was looking for.
>
> Thanks,
>
> Ben
>
> On 7/7/06, Christian Heilmann <codepo8 at gmail.com> wrote:
> > > 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/
> > --
> >
> > * * Please support the community that supports you.  * *
> > http://evolt.org/help_support_evolt/
> >
> > For unsubscribe and other options, including the Tip Harvester
> > and archives of thelist go to: http://lists.evolt.org
> > Workers of the Web, evolt !
> >
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


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