madcrazy1 Posted September 18, 2011 Share Posted September 18, 2011 I need code to throw validate flag only if no fields are filled Current code below throws validate flag if any field is empty. Many thanks! (a flag has a background of error.png no flag has a background of checked.png) validates errors on all the fieldsets records if the Form has errors in $('#formElem').data() */ function validateSteps(){ var FormErrors = false; for(var i = 1; i < fieldsetCount; ++i){ var error = validateStep(i); if(error == -1) FormErrors = true; } $('#formElem').data('errors',FormErrors); } /* validates one fieldset and returns -1 if errors found, or 1 if not */ function validateStep(step){ if(step == fieldsetCount) return; var error = 1; var hasError = false; $('#formElem').children(':nth-child('+ parseInt(step) +')').find(':input:not(button)').each(function(){ var $this = $(this); var valueLength = jQuery.trim($this.val()).length; if(valueLength == ''){ hasError = true; $this.css('background-color','#FFEDEF'); } else $this.css('background-color','#FFFFFF'); }); var $link = $('#navigation li:nth-child(' + parseInt(step) + ') a'); $link.parent().find('.error,.checked').remove(); var valclass = 'checked'; if(hasError){ error = 1; valclass = 'error'; } $('<span class="'+valclass+'"></span>').insertAfter($link); return error; } /* }); Quote Link to comment https://forums.phpfreaks.com/topic/247398-need-to-throw-validate-flag-only-if-no-fields-are-filled/ Share on other sites More sharing options...
goodacre.liam Posted September 24, 2011 Share Posted September 24, 2011 From what I understand from your post, you should just need to change: if (error == -1) To the following: if (error !== -1) Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/247398-need-to-throw-validate-flag-only-if-no-fields-are-filled/#findComment-1272481 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.