mujas mujas - 6 months ago 11
jQuery Question

How to select current day when user was in other months in Datepicker calender by using a clickable button.?

I have an event calender in my magento website.
I need to redirect users to current date while they are in other months.
I have a button called TODAY to write the click event.

EX : now I am in month of march, I want to go to February by clicking the button TODAY.
Please see the image I will post here.

I am unable to publish an image, if any one nee an image for this I can send it to you.
Great pleasure if any one can help me on this. Thank you.
EDIT

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">

<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>

jQuery(function() {

var jqdpopup = jQuery('#event_popup').dialog({autoOpen: false});
var myDate = new Date();
var prettyDate =(myDate.getMonth()+1) + '/' + myDate.getDate() + '/' +
myDate.getFullYear();


jQuery("#date_input").val(prettyDate);
jQuery('.eventslisting_title span').html(prettyDate);
getevents(prettyDate);
var datesArray=["11/02/2014","11/03/2014"];

jQuery(function(){

jQuery('#event_calender').datepicker({
inline: true,
beforeShowDay: function (date) {
var theday = (date.getMonth()+1) +'/'+
date.getDate()+ '/' +
date.getFullYear();
return [true,jQuery.inArray(theday, datesArray) >=0?"eventDate":''];
},
onSelect: function(date, obj){
jQuery('#date_input').val(date); //Updates value of of your input
jQuery('.eventslisting_title span').html(date);
getevents(date);
jqdpopup.dialog( "open" );


}
});

Answer

Check out the setDate method in the datepicker api: http://api.jqueryui.com/datepicker/#method-setDate

To set the date by clicking a button do this:

jQuery("#buttonID").click(function(){
    jQuery('#event_calender').datepicker( "setDate",  "today");
});
Comments