javascript getElementByName doesn't work

Posted by phil on Stack Overflow See other posts from Stack Overflow or by phil
Published on 2010-06-05T14:57:24Z Indexed on 2010/06/05 15:02 UTC
Read the original article Hit count: 184

Filed under:

This simple js script can't set the value of "para". I guess getElementByName doesn't work. But why?

<script>
function fn()
{
document.getElementById("para").setAttribute("name","hi");
document.getElementByName("hi").setAttribute("value","my value is high");
}
</script>

<html>
<input type="button" onClick="fn()" value="click me">
<input id="para" type="text" />
</html>

© Stack Overflow or respective owner

Related posts about JavaScript