Change text value with getElementsByName

I have the text firstName that I want to change its value, but it does not work -

 <input type="text" name="firstName" /> <script LANGUAGE="JavaScript" TYPE="text/javascript"> document.getElementsByName("firstName").[0].value = "New Value " ; </script> 

How to change this value?

+4
source share
1 answer

This is not syntactically valid JS. Remove the excess . :

 // ↓↓ document.getElementsByName("firstName")[0].value = "New Value " ; // ↑↑ 

and the rest will work .

+17
source

All Articles