The code for the second alert command works as intended (it displays the value of the item "b", but the first alert command does not work (it should do the same). Why is this?
<html> <head> <script type="text/javascript"> function getValue() { alert(document.getElementsByName("to").value); alert(document.forms[0].to.value); } </script> </head> <body> <form> <input name="to" type="hidden" value="hoolah" /> <input type="button" onclick="getValue()" value="Get Value!" /> <form/> </body> </html>
javascript
user1146930
source share