Javascript getElementsByName() not working - undefined value

How should I get the value using javascript getElementsByName() ? For some reason it is not working. I am getting only "undefined" value.
0
give a positive ratinggive a negative rating
Hi,

If value is assigned to element and you are getting undefined value, it means there is probably a problem with a javascript function. The function getElementsByName() returns a collection of all elements in the document with the specified name. Even when you use a unique specific name only for one element, you have to set the element's id in getElementsByName() function.

The using of getElementsByName() should look like:

<input name="zip_code" value="12345" />

<a href="javascript:void(0);" onClick="javascript: alert(document.getElementsByName('zip_code')[0].value); ">Get ZIP code</a>

Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us