Reputation: 525
I am trying to access the form elements in a jsp page using the name attribute. this form contains text,textarea and select fields. now in my javascript file i have to get these values.
$("input[name=first_name]").val()
By using this we can get only values of input type fields (for ex:text) and not and fields.
Please help me to resolve this.i want to use jquery code for this.
Upvotes: 0
Views: 3380
Reputation: 5084
Use
var form = $("#form_id");
//form['name_of_input_field']
this is much quicker than using selectors.
Upvotes: 0
Reputation: 1038800
You could use the :input
selector:
$(':input[name="first_name"]').val()
Also note that having multiple form elements (text fields, textareas, select boxes) with the same name is probably wrong.
Upvotes: 3
Reputation: 18542
You don't need the type of element in the selector:
$("[name=other_name]").val()
Upvotes: 1