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.