jquery - error messages were produced once only -
i have below jquery code check start , end dates , error message shows once , if user changed end date wrong values no error messages produced. there i'm missing ?
$('input[name="enddate"]').change(function(){ var startdate=$('input[name="startdate"]'); var enddate=$('input[name="enddate"]'); var errorspan= $('.errorspan'); $.ajax({ url:'${createlink(controller:'empref', action: 'checkservicedatesajax')}' , type:'post' , data:{startdate:startdate.val(), enddate:enddate.val()} , success: function(xmlhttprequest, textstatus, jqxhr) { }, error: function(xmlhttprequest, textstatus, errorthrown) { errorspan.html(" <font color='red'>"+xmlhttprequest.responsetext+"</font>").fadeout(5000); enddate.focus(); } }) });
this because when call fadeout()
on error message container, sets display
property none
. when try reuse same element, hidden. can make work ensuring element visible before fading out:
error: function(xmlhttprequest, textstatus, errorthrown) { errorspan.html(" <font color='red'>"+xmlhttprequest.responsetext+"</font>") errorspan.show() errorspan.fadeout(5000); enddate.focus(); }
Comments
Post a Comment