Get the value of text input field in JavaScript
Question:
How to get the value of text input field in JavaScript? Answer:
const inputValue1 = document.getElementById('input-field-id').value;
Description:
To get the value of an HTML text input
element you can use the value
property of the element. To get the element you can use the document.getElementById
method or if you want a more generic, jQuery-like syntax use the document.querySelector
method.
Reference:
HTML input element value reference
Share "How to get the value of text input field in JavaScript?"
Related snippets:
- Select HTML elements by CSS selectors in vanilla JavaScript
- Play video in fullscreen with vanilla JavaScript
- Exit from fullscreen mode on click in JavaScript
- Toggle fullscreen and normal mode with JavaScript
- Switch browser to fullscreen mode with JavaScript
- Get the value of text input field in JavaScript
- Get element with data- attribute using vanilla JavaScript
- Get the value of selected radio button in JavaScript
- Get selected option from select using JavaScript
- Check if element is hidden in JavaScript
Tags:
html, input, value, text, field, getELementById, querySelector Technical term:
Get the value of text input field in JavaScript