user1220022
user1220022

Reputation: 12075

jQuery number of inputs in a form

I have a form and I want to know the number of inputs in a form.

I am trying to access it like this:

alert($(this).parents("form").(':input').size());

Where this function is called from a button click in the form, using .parents() to get the correct form from the page and I need a handler to the input such as using $('input').size() but for a specific form.

Can anyone help me out here?

Upvotes: 1

Views: 72

Answers (3)

Sagiv Ofek
Sagiv Ofek

Reputation: 25270

$(this).parents("form:input").length

Upvotes: 1

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

try this:

  alert($(this).parents('form :input').length);

Upvotes: 0

Curtis
Curtis

Reputation: 103348

For a count of the number of inputs in that form element, you can do:

$(this).parents("form").find('input').length

References:

Upvotes: 5

Related Questions