Let's say I have an input field like this:
<input type="text" id="input" value="This is my value">
How can I get the attribute value? In jQuery, I can easily get it with:
$('#input').val() //-> This is my value
How do I do so using pure JavaScript?
To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.
Definition and Usage. The value property sets or returns the value of the value attribute of a text field. The value property contains the default value OR the value a user types in (or a value set by a script).
You can get the value by targeting the ID.
Where inputID
is the ID of your input or textarea:
document.getElementById('inputID').value;
You can also do it by targeting the name attribute.
Where inputID
is the Name of your input or textarea:
document.getElementsByName('inputID')[0].value;
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