oshirowanen
oshirowanen

Reputation: 15925

jQuery datapicker execute function when date has been selected

Is it possible to execute a custom function when a date is selected from the jQuery datepicker?

I have tried using the onClose option, but that just seems to execute the function when the page loads for the first time, after that I can change the date as many times as I want and the function does not execute.

Upvotes: 1

Views: 1129

Answers (4)

ajtrichards
ajtrichards

Reputation: 30565

$( "#datepicker" ).datepicker({
    onSelect: function(dateText, obj){
         alert(dateText); // Or do something else you need it to do
    }        
});​

I've saved an example in a jsFiddle - http://jsfiddle.net/GZE7D/

Upvotes: 1

Eli
Eli

Reputation: 14827

You can try running your code in onSelect function:

$('.datepicker').datepicker({
    dateFormat: 'dd-mm-yy',
    numberOfMonths: 1,
    onSelect: function(selected,evnt) {
         // Run your code here
    }
});

Upvotes: 0

Darrrrrren
Darrrrrren

Reputation: 6078

Use the "onSelect" option. Typing to hit 30 chars.

Upvotes: 0

Bruno
Bruno

Reputation: 5822

Try:

$("#id").datepicker({
    onSelect: function( date ){ 
        // do stuff
    }
});

Upvotes: 1

Related Questions