html5 - Start date End date validation in jQuery -
i have validate start date less end date , end date greater start date using jquery. application using html 5 + thymeleaf.
code :
validation 1:
$('#validfrom').removeclass('hasdatepicker').datepicker({ dateformat: 'dd-m-yy', changemonth: true, changeyear: true, onselect : changeenddate }); function changeenddate() { var d = $("#validfrom").datepicker('getdate'); $('#validto').removeclass('hasdatepicker').datepicker({ mindate : d, dateformat: 'dd-m-yy', changemonth: true, changeyear: true }); }
validation 2:
$('#validto').removeclass('hasdatepicker').datepicker({ dateformat: 'dd-m-yy', changemonth: true, changeyear: true, onselect : changestartdate }); function changestartdate() { var d = $("#validto").datepicker('getdate'); $('#validfrom').removeclass('hasdatepicker').datepicker({ maxdate : d, dateformat: 'dd-m-yy', changemonth: true, changeyear: true }); }
if use either 1 of validations working fine. if use both, validation 1 working. can on issue.
thanks in advance.
because in change method create datepicker again calling , don't pass change listener function again. example:
function changestartdate() { var d = $("#validto").datepicker('getdate'); $('#validfrom').datepicker("destroy"); $('#validfrom').datepicker({ maxdate : d, dateformat: 'dd-m-yy', changemonth: true, changeyear: true, onselect : changeenddate }); }
this way destroy datepicker first , re-initialize onselect method attached. i'm not sure why remove class element, if want destroy element, removing class not solution. must call destroy function.
Comments
Post a Comment