javascript - Calendar Keep Selected Date After Passing PHP Variable -
i use calendar code below minor modification made, anyway when select date, calendar highlights date selected great when pass selected date , redirect url, calendar looses selected date , no longer highlighted on next page, since passing variable, how can edit calendar code , pass selected variable selected date known , highlighted on calendar in next page (same calendar).
g_globalobject = new jsdatepick({ usemode:1, isstripped:true, target:"div3_example" }); g_globalobject.setonselecteddelegate(function(){ var obj = g_globalobject.getselectedday(); if (obj.month.tostring().length < 2) { var date = obj.year + "-0" + obj.month + "-" + obj.day //alert(date); window.top.location.href = '..index.php?pdate=' + date; }else { var date = obj.year + "-" + obj.month + "-" + obj.day //alert(date); window.top.location.href = '..index.php?pdate=' + date; } });
jsdatepick has configuration option called selecteddate
can used pre-select date. can parse query string , feed option @ initialization.
sadly, turns out selecteddate
buggy , disable date picker when used. there fix in 15437091/jsdatepick-using-a-selected-date in answer of user cesar referencing selecteddate - problem im jsdatepick javascript - modul (javascriptcalendar.org) (in german) requires modification of source. rather that, can use wrapping:
// duplicate original function jsdatepick.prototype.setconfiguration_original = jsdatepick.prototype.setconfiguration; // redefine function jsdatepick.prototype.setconfiguration = function() { // call original function jsdatepick.prototype.setconfiguration_original.apply(this, arguments); // use "selecteddate" if(this.oconfiguration.selecteddate){ this.currentyear = this.ocurrentday.year; this.currentmonth = this.ocurrentday.month; this.currentday = this.ocurrentday.day; this.selecteddayobject = this.oconfiguration.selecteddate; this.flag_adaywasselected = true; } } // parse query string selected date var pdate = location.search.match(/[\?&]pdate=(\d+)-(\d+)-(\d+)/); pdate = pdate ? {year:parseint(pdate[1]), month:parseint(pdate[2]), day:parseint(pdate[3])} : null; var g_globalobject = new jsdatepick({ usemode:1, isstripped:true, selecteddate: pdate, target:"div3_example", });
Comments
Post a Comment