danion: getElementsByName liefert NULL

Beitrag lesen

IE works correctly on elements that CAN'T have a name attribute.
It works incorrectly, however, on elements that can.

Firefox handelt das name Attribut fehlerfrei, Internetexplorer stattdessen das id Attribut also muss man es über die 2 Attribute handeln. So seh ich das nach den Versuchen auch.

<html>
<head>
<script language="JavaScript">
function init()
{
 var myInput=document.createElement("input");
 myInput.name="testInput";
 myInput.id="testInput";
 myInput.value="hurz";
 document.getElementsByTagName("body")[0].appendChild(myInput);
}
function test()
{
 var object;
 if(document.getElementsByName("testInput")[0].value)
  object=document.getElementsByName("testInput")[0].value;
 else
  object=document.getElementsById("testInput")[0].value;
 alert(object);

}
</script>
<body onLoad="init()">
<button onclick="test()">Test aufrufen</button>
</body>
</head>
</html>