Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: How can I reference a non-standard attribute in Netscape


Message #1 by "Paul Stearns" <pauls@c...> on Mon, 11 Jun 2001 03:38:18
I need to be able to reference an non-standard attribute of an input tag
from JavaScript. It works in IE but not Netscape.

An example;

==========================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>

<Script Language=JavaScript>

function testit(){
    alert(document.myform.field1.myattribute)
}

</script>

</head>
<body>

<form  name="myform">
<input name="field1" type="text" myattribute="attribute1"
onblur="testit()">
</form>

</body>
</html>
=========================

In IE it will display an alert with "attribute1" in it. In Netscape 4.x
it will display an alert with "undefined" in it.

Is there a way to access this attribute from NetScape? How?

By the way I got the idea to do this from an article on Netpedia written by
Alexander Nakhimovsky. In the article he states;

--------------------
As you probably know, you can add your own customized attributes to HTML 
elements. For instance, if you have a form with a text-input element in 
it, you can give it an attribute called validator:

<form id="exampleForm">

<input type="text" name="input1" validator="whatsThisFor?">

...

</form>

The attribute will be ignored by the rendering engine of the browser and 
have no impact whatsoever on how the page is displayed. However, just as 
the "real" attributes, it is exposed to the scripting language: it is 
possible to refer to the attribute i n JavaScript, and to examine its 
value. The rules for referring to elements are, of course, different in 
IE4 and N4; our examples will only work in IE4 or later, but the same 
principles apply to Netscape pages:
------------------------

OK, if the same principles apply, would someone please point me to where I 
can find these principles?

Paul

  Return to Index