Making my own attibutes for HTML Tags

Giganews Newsgroups
Subject: Making my own attibutes for HTML Tags
Posted by:  RIck Measham (ric…@isite.net.au)
Date: Tue, 16 Sep 2003

Is there some way to access an attribute to a tag that I've made up? Eg:
        <INPUT type="text" name="phone" size=12 validate="area_phone_au">

I can get the type using:
        document.formname.phone.type

But I don't seem to be able to access the 'validate' attribute:
        document.formname.phone.validate

Anyone know if there's a way? If there's not, is there some other simple way
to specify validation information for a field? I could do something like:

        <INPUT type="text" name="phone" size=12>
        <SCRIPT> add_validation(document.formname.phone, "area_phone_au") </SCRIPT>

        <INPUT type="text" name="state" size=4>
        <SCRIPT> add_validation(document.formname.state, "format:AAA?") </SCRIPT>

The 'validate' function would then store the reference to the field and the
validation information. On submit, we validate all the fields by searching
all the references to see if they're in the form we want. (Have to work
that one out too!)

I'd prefer not to have to add script elements to do the validation. I'd
prefer to be able to store it in an attibute to the field. Of course I
could add it to an eventhandler for the field such as:
        <INPUT type="text" name="state" size=4 onFocus="add_validation(this,
"format:AAA?")">

But that's still messier than I'd like it. Of course, all JS cases,
add_validation would have to check to see if it already knew about the
field!

Thanks for your help.
Cheers!
Rick

Replies