jQuery UI Datepicker set display month -
i need set display month on datepicker in click event of control. possible? can't use setdate method since set specific date, whereas i'm trying emulate prev/next month buttons on datepicker.
edit: i'm using inline datepicker https://jqueryui.com/datepicker/#inline
html:
<input type="button" onclick="changemonth(1);" />
javascript:
function changemonth(month) { //set month on datepicker $("#datepicker").??? }
assuming have mm/dd/yyyy mask, like in demo this:
upd2. using datepicker api
function changemonth(month) { var initialval = $('#datepicker').datepicker('getdate') curmonth = date.getmonth(), if(month > 0 && curmonth < 12){ initialval.setmonth(curmonth + 1) } if(month < 0 && curmonth > 1) { initialval.setmonth(curmonth - 1) } $('#datepicker').datepicker('setdate', initialval); }
the calling changemonth(1)
or changemonth(-1)
should change date in datapicker field.
upd1. if you're using inlined version
you can "click" buttons jquery click event:
$('#datepicker .ui-datepicker-prev').click() // month $('#datepicker .ui-datepicker-next').click() //month forward
Comments
Post a Comment