Ccna final exam - java, php, javascript, ios, cshap all in one. This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Friday, June 1, 2012
How do I get the value of a textbox using jQuery?
I can get the element like this $("#txtEmail") but I'm not sure how to get the actual value.
Noticed your comment about using it for email validation and needing a plugin, the validation plugin may help you, its located at http://bassistance.de/jquery-plugins/jquery-plugin-validation/, it comes with a e-mail rule as well.
Just Additional Info which took me long time to find.what if you were using the field name and not id for identifying the form field. You do it like this:
For radio button:
var inp= $('input:radio[name=PatientPreviouslyReceivedDrug]:checked').val();
For textbox:
var txt=$('input:text[name=DrugDurationLength]').val();
I think there's a .val() method
ReplyDeleteEdit:
If you've got an input with an id of txtEmail you should be able to 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")
Hope that helps!
Use the .val() method.
ReplyDeleteAlso I think you meant to use $("#txtEmail") as $("txtEmail") returns elements of type <txtEmail> which you probably don't have.
See here at the jQuery documentation.
Also jQuery val() method.
Noticed your comment about using it for email validation and needing a plugin, the validation plugin may help you, its located at http://bassistance.de/jquery-plugins/jquery-plugin-validation/, it comes with a e-mail rule as well.
ReplyDeletePossible Duplicate:
ReplyDeleteJust Additional Info which took me long time to find.what if you were using the field name and not id for identifying the form field. You do it like this:
For radio button:
var inp= $('input:radio[name=PatientPreviouslyReceivedDrug]:checked').val();
For textbox:
var txt=$('input:text[name=DrugDurationLength]').val();