Reputation: 7081
Absolute noob question.
I have a form
<form>
<input type="text" id="cars" name="cars"/>
</form>
When the user clicks on a link , my jquery function needs to pick up the current value of this input field.
How do I retrieve this value? Doing a $("#cars").val gives me a block of html and not the string typed in by the user, Also $("cars").text throws a null value.
Any suggestions?
Upvotes: 0
Views: 1118
Reputation: 630637
Make sure you're calling it as a function (with parenthesis!), $("#cars").val()
will give you want you want here.
For example:
$("button").click(function() {
alert($("#cars").val());
});
You can test it out here, without the parenthesis you're getting the function, not executing it and getting the result, see what I mean in a demo of that here.
Upvotes: 4