liquinas Posted August 21, 2008 Share Posted August 21, 2008 Hi all! I have this function which checks for empty fields that have class="required" on a form before submitting. What I want to know is if I can use more than one qualifying flag. For example both class="required" and class="peanut" but not anything else. function validate() { var result = $('.required').map(function (index, domElement) { var flag = "true"; if ($(this).val().length < 1) { $(this).css({backgroundColor:"red"}); flag = "false"; } else { $(this).css({backgroundColor:"white"}); } return flag; }); return result; } Thanks in advance for any advice Link to comment https://forums.phpfreaks.com/topic/120776-solved-form-validation-function/ Share on other sites More sharing options...
lemmin Posted August 22, 2008 Share Posted August 22, 2008 You can specify more than one class by separating them by spaces: <p class="require peanut"> http://msdn.microsoft.com/en-us/library/ms533560(VS.85).aspx Link to comment https://forums.phpfreaks.com/topic/120776-solved-form-validation-function/#findComment-623062 Share on other sites More sharing options...
liquinas Posted August 22, 2008 Author Share Posted August 22, 2008 Thanks for the reply. What I'm looking for is for .peanut to be an alternate required class in the first line of the function. Something like: var result = $('.required' OR '.peanut').map(func... How could I write this? Link to comment https://forums.phpfreaks.com/topic/120776-solved-form-validation-function/#findComment-623216 Share on other sites More sharing options...
corbin Posted August 22, 2008 Share Posted August 22, 2008 Is that jQuery? If so: var result = $(".required,.peanut").blah(); Link to comment https://forums.phpfreaks.com/topic/120776-solved-form-validation-function/#findComment-623338 Share on other sites More sharing options...
liquinas Posted August 23, 2008 Author Share Posted August 23, 2008 THANK JOO! Link to comment https://forums.phpfreaks.com/topic/120776-solved-form-validation-function/#findComment-623604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.