Skip to content Skip to sidebar Skip to footer

How To Prevent Jquery Datepicker From Popping Up On Initial Page Load But Still Scroll To Datepicker Textbox

I have something similar to the following Javascript: $(function () { $('#txtDate').focus(); $('#txtDate').datepicker({ ... autoOpen: false, ...

Solution 1:

Try this:

var initialized = false;
$(function () {
    $("#txtDate").focus();
    $("#txtDate").blur(function(){
        if(!initialized){
            $("#txtDate").datepicker({
                autoOpen: false
            });    
            initialized = true;
        }
    });
});

Example

http://jsfiddle.net/pQALk/3/

Solution 2:

This jQuery works:

$(function () {
    $(".txtDate").focus();
    setTimeout(function() {$(".txtDate").datepicker({
        autoOpen: false
    });},10);
});

It's a bit of a hack - added a delay of 0.01 seconds before binding the datepicker, so the focus happens before the datepicker is bound and so doesn't trigger the datepicker. http://jsfiddle.net/pQALk/2/

Post a Comment for "How To Prevent Jquery Datepicker From Popping Up On Initial Page Load But Still Scroll To Datepicker Textbox"