Question

I would like to add links on every date in my calendar. For example, if I click on the 25 august 2010, I would like that the page gets redirected to : xxxxxx/25082010/

(ddmmyyyy)

The plugins is this one : http://keith-wood.name/datepick.html

I can add an event when a date is selected (onSelect) but I can't get the date in the good format (ddmmyyyy) and the link to be made.

<script type='text/javascript' >
    $(document).ready(function(){

$('#mindate').datepick({
    dateFormat: 'yyyy-mm-dd',
    defaultDate: '2010-10-01',
    minDate: '2009-10-01', 
    maxDate: '2010-10-01',
    onSelect: function(dates) { alert('The chosen date(s): ' + dates); }, 
    showTrigger: '<button type="button" class="trigger">Change</button>'});

});
</script>

The "onSelect" give me the date like this: The chosen date(s): Wed Aug 25 2010 00:00:00 GMT-0400 (Eastern Daylight Time)

Thanks

Was it helpful?

Solution

You can use some of the built-in methods on the Date object to format the date that the picker is returning:

alert('The chosen date(s): ' + dates.getDate() + 
                               dates.getMonth() + 
                               dates.getYear());

OTHER TIPS

I'd switch to jQuery UI datepicker if it's not too late, that script has far better support and features http://jqueryui.com/demos/datepicker/ And it has different types of dates and parseDate method.

onSelect: function(dates) { $.datepick.formatDate('ddmmyyyy', dates[0]); }, 

I had a similar problem and got the answer by looking at this fine human being's answer and shouting aha! jQuery DatePick Populating Input - Multiple Clicks Issue

I'm hoping it's just bad documentation and not me being thick (well now us).

But, the problem is that the data passed to the function is an array or object or whatever that junk is called in javascript and just calling it, "dates" in your case seems to run some sort of toString on it.

If you try dates[0] you will be a happy man. And if you have a multi select range (my problem), you want dates[0] and dates[1] and it just words real nice. I wish he'd put this in his docs a bit more clearly as I very much prefer this one to the UI date picker just for range selecting.

Also, if you can add "datepick" to your tags I think that'd be helpful. I wasted a lot of time trying to avoid all the things that automatically think I'm looking for Jquery UI datapicker and not the Jquery datepick datepicker

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top