Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
51
rated 0 times [  52] [ 1]  / answers: 1 / hits: 23897  / 10 Years ago, fri, february 14, 2014, 12:00:00

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?


More From » jquery

 Answers
12

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;

[#72526] Thursday, February 13, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oliverg

Total Points: 453
Total Questions: 101
Total Answers: 100

Location: Liechtenstein
Member since Wed, Dec 8, 2021
2 Years ago
;