- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Forms and Inputs
JavaScript DOM
JavaScript Forms and Inputs
JavaScript reads and sets form values through the
valueandcheckedproperties.
Forms are how most pages take information from a visitor.
value is always a string, even for a number input.
Example
Example
javascript
document.body.innerHTML = '<input id="name" value="Ada">';
console.log(document.getElementById("name").value);The output is Ada.
Reading Form Values
value holds the current contents of a text, number or select input.
checked is a boolean for checkboxes and radio buttons.
