0

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.

1
  • I am trying to get the all fields values at a time as an array.but the above code will give me only input type field values not <textarea> and <select> values in a form. please help me Commented May 11, 2011 at 13:46

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

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

Comments

0

You should use :input selector.

Comments

0

Use

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

this is much quicker than using selectors.

4 Comments

Wouldn't this look for a dom element of type 'form_id' in the same way that $('div') would look for divs?
$('divs') will return object that has id ="divs"
Umm, no, not really, to select by ID you need to use $('#id_of_element') - take note of the hash(#). The selectors are based on CSS syntax.
Yes i forgot about that, im not using jQuery, preffer mootools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.