Setting default date on jQuery datepicker -
i working on project 2 datepicker inputs. when user selects date first datepicker input trying second datepicker input show month of first datepicker input when datepicker pops up.
for example user select date in input 1, lets 3/13/2014. when user clicks on input 2 datepicker default goes current month. when user clicks on input 2 datepicker shows month selected in input 1.
does know how can accomplish this?
so far have tried this:
//this noting can tell var defaultdate = $( "#date1" ).datepicker( "option", "defaultdate" ); $( "#date2" ).datepicker( "option", defaultdate ); //this takes value of input 1 , inserts input 2 var date1 = $.datepicker.parsedate('mm/dd/yy', $('#date1').val()); $("#date2").datepicker( "setdate" , date1 );
in order set value of option, need 3 parameters:
.datepicker("option", "[name of option]", newvalue);
you can change defaultdate option of second datepicker value of first textbox:
$("#date2").datepicker( "option", "defaultdate", $('#date1').val() );
this works since default dateformat mm/dd/yyyy default.
a working demo here: demo
however, demo has visual flaw; can see first datepicker flash default date once select date. in order fix visual flaw, can set defaultdate of first datepicker new value:
$("#date2").datepicker( "option", "defaultdate", $('#date1').val() ); $("#date1").datepicker( "option", "defaultdate", $('#date1').val() );
an updated demo here: demo
Comments
Post a Comment