Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery UI datepicker, onclick of a date , get the date and pass to URL

I have a jquery UI datepicker calendar in an event page(sharepoint page).

$('#datepicker').datepicker();

I need to get the date once user clicks on any date and get that date and pass it to the page url as mypage.aspx?dt=1/12/2012.I have this but not working.

$('.ui-datepicker td a').click(function(){  
        var url=$(location).attr('href');
        var date = $(this.datepicker( "getDate" ));
                if(date != 'null')
            url += '&dt=' + date;           
        window.location.href=url;
        });

Neither is this working..

$('.ui-datepicker td a').click(function() { 
        window.location.href = 'http://mysite/events/Pages/default.aspx?dt=' + $('#datepicker').datepicker().val();
        });

can someone help?

like image 207
Anjana Sharma Avatar asked Jan 18 '12 15:01

Anjana Sharma


1 Answers

try

$('#datepicker').datepicker({
    onSelect: function(dateText, inst) { 
        window.location = 'http://mysite/events/Pages/default.aspx?dt=' + dateText;
    }
});

uses the onSelect event (documented here)

Allows you to define your own event when the datepicker is selected. The function receives the selected date as text and the datepicker instance as parameters. this refers to the associated input field.

like image 197
MikeM Avatar answered Oct 12 '22 14:10

MikeM