What is the best JQuery way to ensure that all input fields with the attribute “required” are completed
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
.filter()method to check the value of each and then check the length property of the result:Note that an attribute named
requiredwill invalidate your HTML.data-requiredwould be valid HTML5, however, or you could just give them all a class and use that as the selector (which would also be more efficient).You could also use one of the validation plugins out there: http://google.com/search?q=jquery+validation.