Get input value in JavaScript without using jQuery?

html, javascript, jquery

Solution

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;

Problem

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?

Original source

Related problems