Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get input value in JavaScript without using jQuery? [closed]

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?

like image 897
kyr Avatar asked Feb 14 '14 14:02

kyr


People also ask

How to get input value jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

What is input value in JavaScript?

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).


1 Answers

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;
like image 178
AfromanJ Avatar answered Oct 14 '22 15:10

AfromanJ