JavaScript for WordPress Forums Vanilla JavaScript Uncaught Type Error Reply To: Uncaught Type Error

Zac Gordon

Good question.

The selecting of elements from the DOM is separate from changing the value attribute.

When selecting with getElementsByName it will return an array of values, even if there is only one matching element. So you would first have to get the item from the array you want, then change the value of that element.

It is likely not working because you are trying to change the value of the array, which won’t work, rather than one of the elements in the array.

This is a good question because some selector methods like getElementById only return one value, whereas selectors like getElementsByName will return an array of values.

Hope this helps!