here is a link to a jsfiddle if you would like to play with it yourself
Using javascript
and html
only. This will update the textbox with the value selected onchange
.
By setting the onchange
attribute on the select tag, you register the updateInput()
function as a listener to the onchange
event.
Then inside the function you can use document.getElementsByName()
to access the elements and manipulate their values. Notice that document.getElementsByName()
returns an array-like collection of elements, therefore requiring us to select the first element like so
document.getElementsByName("elementNameGoesHere")[0]
index of the element we want to select goes here --------^
here is a link to a jsfiddle if you would like to play with it yourself