user603749
user603749

Reputation: 1763

jquery datepicker does not allow to focus to another field with onClose or onSelect

I am stumped here. I would like to focus to another field after a user has clicked on a date. The current input gets the value. But I want to automatically go to another input field so they dont have to tab or click to it.

Here is the exact code adding what you suggested. It doesn't work in Safari and Firefox. Did not test with IE. What it does, it flashes the #duedate calendar and the goes back to focus on #shipdate with no calendar anymore.

See anything wrong here? Thank you.

$(function(){
    $("#shipdate" ).datepicker({
    showOn: 'both',
    buttonImage: "/images/calendar.gif",
    buttonImageOnly: true,
    minDate: 0,
    onSelect: function(x,y){
        /*$("#duedate" ).val($("#shipdate" ).val());*/
        $("#duedate" ).focus();
        }
    });

    $("#duedate" ).datepicker({ showOn: 'both', buttonImage: "/images/calendar.gif",
            buttonImageOnly: true,minDate: 0});
});

Upvotes: 1

Views: 1148

Answers (1)

cyrotello
cyrotello

Reputation: 747

Use onClose instead of onLoad:

onClose: function(x,y){
    $("#duedate").focus();
}

It seems that there is some issue with using onSelect to do this... what's probably happening is the first instance is closing the datepicker, while the second instance is opening it -- which is why it 'flashes'.

You can optionally use $('#duedate').datepicker("show"); instead of $("#duedate").focus();.

Upvotes: 2

Related Questions