I am trying to test this small feature and I believe I wrote everything correctly, however it does not show up in my console.log. Is there something I am over looking?
var inputChange = function() {
var inputVal = document.getElementById("input").value;
console.log(inputVal)
};
form{
width: 300px;
height: 75px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
</head>
<body>
<form>
<input id="input" type="text" name = "input" placeholder="Type Something"/>
<input type="submit" onclick ="inputChange()"/>
</form>
</body>
</html>
HTML inputs
of type submit
send their form whenever you click on them, so the script is getting called, and you're seeing the output briefly, but then the page is getting reloaded and the console is getting cleared. Change
<input type="submit" onclick ="inputChange()"/>
to
<input type="button" onclick ="inputChange()"/>
and you should be good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With