Checking multiple input fields...
Hello!
I am trying to check couple of text fields if they are filled. But with my code:
If I fill first field I get "All filled!". even if I didn't fill the others..
If I fill all fields except first one I get "All not Filled" which is good!
However, I wanna display "All filled" if all the MustField class fields are filled. What's wrong with my code?
- $(document).ready(function() {
-
- $("#submit").click(function() {
-
- if($(".MustField").val().length == 0) {
- alert("All not filled");
- }else{
- alert("All filled");
- return false;
- }
- });
- <form action="" method="post">
- 1:<input type="text" class="MustField"/>
- 2:<input type="text" class="MustField"/>
- 3:<input type="text" class="MustField"/>
- <input type="submit" id="submit" value="submit" />
- </form>