0

I have 9 input's and 30 textarea's in one form. A few of the inputs are automatically filled. I need to count the ones that are filled.

Is there a javascript, ajax, or any other script language that can do this? My form can be seen at:

http://www.41q.org/admin/data/register_form.php

(This webpage is included in another secured webpage via javascript)

Thanks.

1 Answer 1

2
var elements = document.forms['form_register'].elements,
    not_filled = 0;
for( var i = 0, l = elements.length; i < l; i++ ) {
   if( elements[i].value.length === 0 ) {
       // do something to the element?
       not_filled++;
   }
}
console.log(not_filled, " elements were no filled");

Note: i'm not sure if JS should be the only validation you run... server side validation is always recommended.

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

3 Comments

How do I get the number to show up in a field and can it be outside the form so it does not get counted?
where i have console.log you would just take that value and put it anywhere you would like... if this is beyond your javascript skills then a quick refresher of the basics might be a good idea.
but to be a nice guy.... look up getElementById() and appendChild(). also look up replace element content without innerHTML()

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.