How would I take user input from html and set it to a variable in javascript?
This is what i'm trying to implement:
<p>
<label>how old are you?</label>
<form id="form" onsubmit="return false;">
<input style=position:absolute;top:80%;left:5%;width:40%; type="number" id="userInput">
<input style=position:absolute;top:50%;left:5%;width:40%; type="submit" onclick="age()">
</form>
<script type="text/javascript">
function age()
{
var input = document.getElementById("userInput");
alert(input);
}
if(age<20)
{
alert(YOU ARE UNDER 20)
}
</script>
</p>
alertif your printing a string eg :alert("YOU ARE UNDER 20")