Philip007 Philip007 - 1 year ago 138
Javascript Question

javascript getElementByName doesn't work

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

function fn()
document.getElementByName("hi").setAttribute("value","my value is high");


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

Answer Source

It's getElementsByName . Note the plural. It returns an array-like NodeList of elements with that name attribute.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download