Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the value of a textbox using jQuery?

Tags:

jquery

I can get the element like this $("#txtEmail") but I'm not sure how to get the actual value.

like image 332
Micah Avatar asked Jan 20 '09 23:01

Micah


People also ask

How can get textarea value in jQuery using ID?

We can get the value of textarea in jQuery with the help of val() method . The val() method is used to get the values from the elements such as textarea, input and select. This method simply returns or sets the value attribute of the selected elements and is mostly used with the form elements.

How can check empty textbox value in jQuery?

To check if the input text box is empty using jQuery, you can use the . val() method. It returns the value of a form element and undefined on an empty collection.


1 Answers

There's a .val() method:

If you've got an input with an id of txtEmail you can use the following code to access the value of the text box:

$("#txtEmail").val() 

You can also use the val(string) method to set that value:

$("#txtEmail").val("something") 
like image 137
neilprosser Avatar answered Oct 13 '22 18:10

neilprosser