jquery: when select list value is changes, date field is required -


i've got form , when status select list changed, status effective date needs required field.

function checkstatuses(){        $('.status').each(function (){         thisstatus = $(this).val().tolowercase();         thisorig_status = $(this).next('.orig_status').val().tolowercase();         target = $(this).parents('td').nextall('td:first').find('.datepicker');          if ( thisstatus  == thisorig_status  )         {            target.val('');         }         else if( thisstatus == 'production' || thisstatus == 'production w/o appl')       {          target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>').focus();          alert('the status effective date required.');          return false;         }         else         {            target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>');            return false;         }      });   } 

the return false not preventing form submitting anyway. form above being called function such:

return checkstatuses();

your function right returning nothing. return statements have in jquery loop. return false break $.each() loop. returns main function (checkstatuses()) reaches end of codeblock without return statement. having return variable may help:

function checkstatuses(){    var result = true;  //assume correct unless find faults     $('.status').each(function (){         thisstatus = $(this).val().tolowercase();         thisorig_status = $(this).next('.orig_status').val().tolowercase();         target = $(this).parents('td').nextall('td:first').find('.datepicker');          if ( thisstatus  == thisorig_status  )         {            target.val('');         }         else if( thisstatus == 'production' || thisstatus == 'production w/o appl')       {          target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>').focus();          alert('the status effective date required.');          result = false;  //set false meaning not submit form          return false;         }         else         {            target.val('<cfoutput>#dateformat(now(), "mm/dd/yyyy")#</cfoutput>');          result = false;  //set false meaning not submit form          return false;         }      });      return result;  //return result of checks } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -