Help me with document.getElementsByName?

I write a form like:
<form name=“linh” action=“1.php”>
<input type=“text” name=“nguyen” value=“Hello word”>
</form>

I want to get “hello word” from this form by javascript
I tried write:
<script>
var a=document.getElementsByName(“nguyen”);
alert(a);
</script>

But my code don’t run.
Can everyone help me ?
Thanks all !!!

You need to access the form elements:


<form name="linh">
	<input type="text" name="nguyen" value="Hello word">	
</form>	
<script>
	var a = document.linh.nguyen.value; // document - form name - input name - value
	alert(a);		
</script>

The reason you’re code doesn’t work is that getElementsByName() returns a nodelist not the value.


var a=document.getElementsByName("nguyen");
alert(a[0].value);

oki, thanks all very much !