Roger Ineichen wrote:
Hi all
We at the Zope3 dev mailinglist have a question to
you genious JQuery developers. We run into a IE 6&7 issue
related to DOM element id and name.
The following two onclick handler return both
Bar as value in IE 6 and 7. Does anybody know why?
<html>
<head><title>test</title></head>
<body>
<form>
<input type="submit" name="foo" id="bar" value="Bar" />
<input type="submit" name="baz" id="foo" value="Foo" />
</form>
<span onclick="javascript:alert(document.getElementById('bar').value)">bar
(ok)</span>
<span onclick="javascript:alert(document.getElementById('foo').value)">foo
(problem on IE 6 & 7)</span>
</body>
</html>
This is a known IE bug. Id and the name attribute share the same
namespace in IE giving you the (unexpected) result you're talking of
(getElementById gives you the first occurence of an element with the
given id or name). I wonder what the developers were thinking...
jQuery has fixed this by the way when using an id selector.
What rule whould you recommend for generate
id and name attributes for a framework which
generates input fields, buttons etc.
In the new form framework we are developing right now,
do we generate element id and name values like:
id="form-widgets-lastname" name="form.widgets.lastname""
Is this acceptable or is there any reason using another
naming convention for element ids and names?
I haven't seen periods in name attributes yet, but they are allowed per
HTML spec. Another option would be to use the underscore:
id="form-widgets-lastname" name="form_widgets_lastname"
What is more important is to avoid that a name attribute matches an id,
which both variants do provide.
-Klaus