<input type=”text” id=”someId”>
Once the textbox is created with the id of “someId” we can use getElementById to capture the value like so:
If we walk through this whole command we see that it starts at the whole document, then it narrows into an element (or tag) that has an id of “someId” and once it selects that it gets its value. The value is whatever the user typed in. The last thing is we would need to save that value in a variable or alert it out or do something else with it. We can do that like so:
var someVar = document.getElementById(“someId”).value;
alert(someVar); // or
Now that you can capture user input, you are able to take that and do all kinds of things with it like form validation, mathematical calculations, etc. If you’d like to learn more be sure to check out our web design/development courses. Have an amazing day!