Count visible and active inputs in my form

Asked

Viewed 1,115 times

1

Well, I know that the Jquery Validation does something similar, because it only blocks a required field, if it is active, see example(In this case, if Voce accepts the "Please agree to our policy" it activates the 3 comboBox below and the validate becomes active for them too).

I’m using the function JQuery find that way:

function calc(){
    alert($("#meuForm").find(".form").size());
}

On my form I put it to him to find all fields with the class="form"

My big problem is that there are invisible fields, and inactive fields, but even so he keeps counting them..... Some help?

2 answers

3

To get the number of inputs visible and enabled, taking into account that you put the form class in all:

alert($(".form:visible").not(":disabled").length);

Example: http://jsfiddle.net/yadvs398/

2


First of all I do not understand the need to define class="form" for each field but assuming it is a special requirement for the intended, I would like to refer to a form that I consider more acceptable using Jquery.

$("#meuForm").find('input[type=text]')

However and going against the requested is possible to get with the ':Visible'

$("#meuForm:visible").each(....);

or

$("#meuForm").not(":visible").each(....);

to finish I put another way to get all fields except the 'Hidden''!

$(":input:not([type=hidden])") 
  • Ummmm show @chambelix.... you can do something like this: if($("#meuForm").find('input[type=text]:visible')){.....} ? If it does, you’re killing my problem here

  • $("#meuForm"). find('input[type=text]'). filter(':Visible')... solved?

  • kkk not.... if possible, ride a jsfiddle bro, I think Voce did not understand my doubt....

  • I put several ways to get only fields that are not 'Hidden' or other words that are not visible

  • The initial question was... Count visible and active inputs in my form... ;/

  • OK Marcelo, I thought it would be enough to put the tags...to count just put the command length... example number of visible fields: $("#meuForm"). find(":input:not([type=Hidden])"). length

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.