Monday, January 14, 2008

getAttribute -- problem on IE (Internet Explorer 6/7) -- YUI is affected

getAttribute function on yahoo has problems with form( till now I've found it with form element only).

<html>
<head>
</head>
<body>
<script>
function getAtr(){
alert(document.getElementById("mform"));
alert(document.getElementById("mform").getAttribute("action"));
};
window.onload=getAtr;
</script>
<form action="hello" id="mform">
<input name="action" value="i m not taking action"/>
</form>
</body>
</html>


Save above code in some file and open it with IE/FF/Safari.
Expected output is an alert saying "hello". But IE 6/7 prints object.

The culprit is input tag which is child of form. The name of the input tag is action and this input object is printed in alert.
Solution: Not to use action as input parameter in a form (specially when you will be manipulating the form in JavaScript.

YUI dialog is affected by this bug of IE.

2 comments:

xyz said...

This is a bug in IE (regardless of the YUI Library)

IE incorrectly returns elements by NAME or ID using this method (whichever it finds first), and it is NOT case sensitive.

See the bugs 152, 154 below:
http://webbugtrack.blogspot.com/2007/08/bug-152-getelementbyid-returns.html
&
http://webbugtrack.blogspot.com/2007/09/bug-154-getelementbyid-is-not-case.html

The solution provided will get around the main issue (although if you want a case sensitive search, you'll need additional tweaking)

Zimbabao said...

Yeah .. I know its IE bug. Since I mentioned YUI because its affected directly and took my one night sleep.

Thanks for the links. Your blog is good.