Problem preventing form submission
I have a very simple script that checks to see if any fields with the class of 'require' are empty. If any of them are, then I want the script to prevent form submission.
Here is what I currently have:
- // prevent form submission if required fields are empty
- $(document).ready(function() {
- $('#frm-contact').submit(function() {
- if ($('#frm-contact .require').val() == '') {
- alert('Please make sure that all of the fields marked with a * are filled in.');
- return false;
- }
- })
- })
But if only one of the fields has a value then that is enough for the form to be submitted. I need it so that all of the required fields need a value inside them.
Here is an older script I made, but I just can't seem to stop the form from submitting!!
- // prevent form submission if required fields are empty
- $(document).ready(function() {
- $('#frm-contact').submit(function() {
- $('.require').each(function() {
- if ($(this).val() == '') {
- alert('Please make sure that all of the fields marked with a * are filled in.');
- var returnCheck = 0;
- }
- })
- if (returnCheck == 0) {
- return false;
- }
- })
- })
If anyone has any ideas that would be great :D