By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,568 Members | 1,194 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,568 IT Pros & Developers. It's quick & easy.

custom attributes in firefox

P: n/a
I am building custom attributes as a means to pass data from the client
to the server. To accomplish this task, a class of "postback" is
applied to a link or button. When the link or button is clicked,
custom attributes are parsed from the link and submitted to the
application as hidden form fields. The code below better illustrates
the HTML:

<a class="postback" c:myAttribute1="value"
c:myAttribute2="value">submit</a>

This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2". The server code
is case-sensitive, so it does not get the proper value. I was
wondering if there were any ways to mitigate this problem on the
client. I understand that there are many server-side solutions.
Additionally, I understand that the w3c recommends that attributes
should be case-sensitive. However, I have a need to make this work.

Sep 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
VK

mr****@gmail.com wrote:
This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2".
HTML is case-insensitive, so are its tag names and attribute names (but
not attribute values). In this respect <a FOO="bar">, <a Foo="bar"or
<a foo="bar"is all the same for all browsers. But for the internal
representation (say for DOM Inspector display) UA "normalize" attribute
names by bringing them to one case. IE "normalize" to upper case, FF
"normalize" to lower case, and someone maybe normalize it to
camel-case, I donno :-)
DOM methods hasAttribute, getAttribute, setAttribute in IE have
additional argument to switch the "normalization" off/on, but you check
on mozilla.org if they have this extension (possibly not).
The server code
is case-sensitive, so it does not get the proper value.
As you cannot predict the "normalization" results for UA, do
normalization yourselve cerver-side before process data (say everything
to upper case). That seems as the easiest solution. I presume you don't
have any burning necessity to have different attributes differing by
their case only like Foo and FOO ;-)

Sep 19 '06 #2

P: n/a


mr****@gmail.com wrote:

The code below better illustrates
the HTML:

<a class="postback" c:myAttribute1="value"
c:myAttribute2="value">submit</a>
Does that validate as HTML 4? Or as XHTML 1?
This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2".
The JavaScript engine? That implements stuff like numbers, boolean,
strings, Date but does not implement any host objects like HTML element
objects.
What JavaScript code are you using exactly, to at least give us a chance
to try to understand what you do?

Additionally, I understand that the w3c recommends that attributes
should be case-sensitive. However, I have a need to make this work.
Well you could serve XML to Firefox, then I am sure it follows the rules
of XML and case-sensitivity:
<http://home.arcor.de/martin.honnen/javascript/2006/09/test2006091901.xhtml>
Despite your beliefs of what the JavaScript engine does.

If you let stuff parse by an HTML/SGML parser then expect some case
folding or case normalization to be done, for instance the SGML parser
the W3C validator uses normalizes attribute names to all upper case, see
the parse tree in
<http://validator.w3.org/check?uri=http%3A%2F%2Fhome.arcor.de%2Fmartin.honn en%2Fjavascript%2F2006%2F09%2Ftest2006091901.html& charset=%28detect+automatically%29&doctype=Inline& sp=1&verbose=1>

And what does it help if you adapt your code for (some version of)
Firefox? Another browser might do something different with its tag soup
parser. Custom attributes in HTML are not really reliable, and if you
even want case-sensitivity then you have choosen the wrong approach for
that validation feature you want.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 19 '06 #3

P: n/a
Thanks. I am serving HTML 4.01. I do not think it validates. Martin,
I learned a lot from your examples.

The following would be a good representation:

function listAttributes (element) {
for (var i = 0, l = element.attributes.length; i < l; i++) {
alert('name=' + element.attributes[i].name);
}
}

I am resigned to the fact that Firefox will normalize these attributes
per this doctype.

For what browsers would you not expect custom attributes to work?

Sep 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.