The getElementsByName() method is use to get the element by name. However be aware of the getElementsByName() method always return an array as output.

<html>
 
<head>
<script type="text/javascript">
    function showElements(){
        alert(document.getElementsByName("myInput")[0].value);
    }
</script>
</head>
<body>
 
<form >
 
    <input name="myInput" type="text" value='testing'><br>
    <br>
    <input name="submit" type="button" onclick="showElements()" 
            value="Show Me Output">
</form>
</body>
 
</html>

Caution
The method always return an array, and we have to use [] to access the value.

For example

alert(document.getElementsByName("myInput").value);

It will prompt out an undefined value

alert(document.getElementsByName("myInput")[0].value);

It will prompt out an expected ‘testing’ value

One more time, there are no getElementByName() exists, it is getElementsByName(), with a ‘s’ :)

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~