Reputation: 6259
I have this HTML code:
<form accept-charset="UTF-8" id="SearchPatient">
<input autocomplete="off" class="form-control" placeholder="Patient suchen .." type="text">
</form>
And this JavaScript function:
$("#SearchPatient").submit(function () {
Patient.all(1, this.find('input').value)
});
How you can guess i try o achieve that when the user submits the form the value of the input is passed to the function Patient.all(int,value)
Somehow i cant figure out how to get the first input in the form, i always get errors! For this code example i get the error:
Object # has no method 'find'
How can i do it correctly?
Upvotes: 0
Views: 1487
Reputation: 3081
If you want the first input child of your form use
$(this).children("input[type='text']:first").val();
Upvotes: 1
Reputation: 304
You are missing a $( ).
The correct code should be:
$("#SearchPatient").submit(function(){Patient.all(1,$(this).find('input').value)});
Upvotes: 1
Reputation: 5226
Use
$(this).find('input').val();
We need to pass this in the jquery function to make use of the jquery methods
Update: as comment , to get the first-
$(this).find('input:first').val();
Upvotes: 3