473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Making my own attibutes for HTML Tags

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
Jul 20 '05 #1
1 1509
RIck Measham <ri***@isite.net.au> writes:
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">
This is not valid HTML, so you shouldn't rely on it working.
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
The DOM element node is not the same as the HTML tag. They are related,
but there doesn't have to be a strict correspondance.

What should work, if the illegal attribute isn't simply ignored, is:
document.forms['formname'].elements['phone'].getAttribute('validate');

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


If you do it like this, you could just build one big array of pairs of
elements and their validation constraint. No need to put the data on
the element.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval...
4
by: Next Generation Technologies Inc. | last post by:
Now what I have is a function that only works in WinIE4+ because it's uses Microsoft proprietary properties and methods: function gmshortcutkeys() { if ((parseInt(navigator.appVersion) >= 4)...
32
by: Cornel Bicutzi | last post by:
Hello, What is the difference between HTML and XHTML... Thanks, ------------------------------------------------------------------------ IT Interview Questions :...
90
by: Ben Finney | last post by:
Howdy all, How can a (user-defined) class ensure that its instances are immutable, like an int or a tuple, without inheriting from those types? What caveats should be observed in making...
13
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
5
by: acord | last post by:
Hi, I m getting annoying display problem when placing javascript tags in a html page. Should the javasscript tags placed at the beginning of a html page before anything start? or placed between...
9
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP...
10
Ajm113
by: Ajm113 | last post by:
Making a History Page for BIG Sites Intro: Ok, let's say after a while your website has grown massive. We're talking search engine, forum and video hosting -- you've got a LOT of content. And you...
7
by: ojsimon | last post by:
Hi I found this script on a forum and have been trying to make it work, but all it returns is a blank screen, i tried using the debug error reporting but got nothing from that either just a blank...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.