I have an input for in my HTML code, and I want to capture the input as a variable in javascript.
HTML:
<form id="answer">
Answer: <input type="text" answer="response"><br>
<input type="button" value="Submit" onclick="answerInput()"> <br><br>
</form>
Javascript:
var answer = document.getElementById('answer').value;
I would expect this to return the value of what was put in the field before submit was hit, but it returns undefined. I need someone to be able to put in a value (in this case a number) and have that number be available as a variable.
Thank you for being patient, I'm new to all this and teaching myself.