Satya
Satya

Reputation: 525

How to get all the form elements values using name attribute

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

Answers (4)

kskaradzinski
kskaradzinski

Reputation: 5084

Use

var form = $("#form_id");
//form['name_of_input_field']

this is much quicker than using selectors.

Upvotes: 0

Sylvain
Sylvain

Reputation: 3873

You should use :input selector.

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

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

raveren
raveren

Reputation: 18542

You don't need the type of element in the selector:

$("[name=other_name]").val() 

Upvotes: 1

Related Questions