So I have some input text fields and a button
<input type=text value="a"/>
<input type=text value="b"/>
<input type=button onclick=???/>
and I want to use the values of those text fields as the parameters in a function that gets called when i click a button, say
function foo(a,b) {
dostuff(a);
dostuff(b);
}
I don’t know what to put in the question marks. So what gets the value of the text inputs, I don’t think document.getElementById gets the value of them, just the element itself.
There are multiple ways to access those values, but the recommended one is to start by giving the input elements ID’s.
Now, you can use
document.getElementByIdto get the element, and then the valueNote the use of ‘ vs ” due to them being nested…
But you could also just pass the ID’s to
foo, and havefoodo thegetElementById-stuff.