jquery datepicker scrolls to top of page after date selected









up vote
0
down vote

favorite












I know this question have been up for a few years ago, but I could not find relevant answer to my problem.



I have made a booking widget plug in seen on the middle on this WP page:
http://mattarahkka.com/the-lodge/#



Afte a date is selected the page scrolls to the top. The date picker remains open and the date remains selected. But why does the page jump to the top?



widget php code:



// include custom jQuery
functieon csf_booking_widget_custom_jquery()

/* REGISTER JS FOR PLUGIN */
wp_register_script('datepicker',plugins_url().'/csf-booking-widget/js/datepicker_2.js');
/* REGISTER CSS FOR PLUGIN */
wp_register_style('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css');
wp_register_style('csf-happy-booking-widget',plugins_url().'/csf-booking-widget/css/happy-booking-widget.css');
/* CALL ALL JS FOR PLUGIN */
wp_enqueue_script('jXquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('datepicker');
/* CALL ALL CSS FOR PLUGIN */
wp_enqueue_style('jquery-ui');
wp_enqueue_style('csf-happy-booking-widget');


function insert_booking_widget()

$content = "<div class="bookingWidget">";
$content .= "<h2>Book Now</h2>";
$content .= "<form method="get" action="https://mattarahkka.happybooking.io/">";
$content .= "<table class="sideTable"><tbody><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-in</span>";
$content .= "<input id="from" name="from" class="checkInsDate" type="text">";
$content .= "</tr><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-out</span>";
$content .= "<input id="to" name="to" class="checkInsDate" type="text">";
$content .= "</tr></tbody></table>";
$content .= "<div class="buttonHolder">";
$content .= "<input class="btn" value="Search available lodgings" type="submit">";
$content .= "</div>";
$content .= "<input type="hidden" name="lang" value="English"/>";
$content .= "</form></div>";

return $content;

add_shortcode('happy-booking-widget','insert_booking_widget');

add_action('wp_enqueue_scripts', 'csf_booking_widget_custom_jquery');


The Js file (datepicker_2):



jQuery(function() 
var dates = jQuery("#from, #to").datepicker(
showWeek: true,
firstDay: 1,
dateFormat: 'yy-mm-dd',
dayNamesMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
weekHeader: "W.",
monthNames: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
onSelect: function(selectedDate)
jQuery.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not(this).datepicker("option", option, date);
autoclose: true;


);
);









share|improve this question





















  • Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
    – Jamie_D
    Nov 11 at 15:27










  • Thank you. Now it is working as intended
    – Pegasuz73
    Nov 11 at 20:57














up vote
0
down vote

favorite












I know this question have been up for a few years ago, but I could not find relevant answer to my problem.



I have made a booking widget plug in seen on the middle on this WP page:
http://mattarahkka.com/the-lodge/#



Afte a date is selected the page scrolls to the top. The date picker remains open and the date remains selected. But why does the page jump to the top?



widget php code:



// include custom jQuery
functieon csf_booking_widget_custom_jquery()

/* REGISTER JS FOR PLUGIN */
wp_register_script('datepicker',plugins_url().'/csf-booking-widget/js/datepicker_2.js');
/* REGISTER CSS FOR PLUGIN */
wp_register_style('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css');
wp_register_style('csf-happy-booking-widget',plugins_url().'/csf-booking-widget/css/happy-booking-widget.css');
/* CALL ALL JS FOR PLUGIN */
wp_enqueue_script('jXquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('datepicker');
/* CALL ALL CSS FOR PLUGIN */
wp_enqueue_style('jquery-ui');
wp_enqueue_style('csf-happy-booking-widget');


function insert_booking_widget()

$content = "<div class="bookingWidget">";
$content .= "<h2>Book Now</h2>";
$content .= "<form method="get" action="https://mattarahkka.happybooking.io/">";
$content .= "<table class="sideTable"><tbody><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-in</span>";
$content .= "<input id="from" name="from" class="checkInsDate" type="text">";
$content .= "</tr><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-out</span>";
$content .= "<input id="to" name="to" class="checkInsDate" type="text">";
$content .= "</tr></tbody></table>";
$content .= "<div class="buttonHolder">";
$content .= "<input class="btn" value="Search available lodgings" type="submit">";
$content .= "</div>";
$content .= "<input type="hidden" name="lang" value="English"/>";
$content .= "</form></div>";

return $content;

add_shortcode('happy-booking-widget','insert_booking_widget');

add_action('wp_enqueue_scripts', 'csf_booking_widget_custom_jquery');


The Js file (datepicker_2):



jQuery(function() 
var dates = jQuery("#from, #to").datepicker(
showWeek: true,
firstDay: 1,
dateFormat: 'yy-mm-dd',
dayNamesMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
weekHeader: "W.",
monthNames: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
onSelect: function(selectedDate)
jQuery.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not(this).datepicker("option", option, date);
autoclose: true;


);
);









share|improve this question





















  • Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
    – Jamie_D
    Nov 11 at 15:27










  • Thank you. Now it is working as intended
    – Pegasuz73
    Nov 11 at 20:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I know this question have been up for a few years ago, but I could not find relevant answer to my problem.



I have made a booking widget plug in seen on the middle on this WP page:
http://mattarahkka.com/the-lodge/#



Afte a date is selected the page scrolls to the top. The date picker remains open and the date remains selected. But why does the page jump to the top?



widget php code:



// include custom jQuery
functieon csf_booking_widget_custom_jquery()

/* REGISTER JS FOR PLUGIN */
wp_register_script('datepicker',plugins_url().'/csf-booking-widget/js/datepicker_2.js');
/* REGISTER CSS FOR PLUGIN */
wp_register_style('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css');
wp_register_style('csf-happy-booking-widget',plugins_url().'/csf-booking-widget/css/happy-booking-widget.css');
/* CALL ALL JS FOR PLUGIN */
wp_enqueue_script('jXquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('datepicker');
/* CALL ALL CSS FOR PLUGIN */
wp_enqueue_style('jquery-ui');
wp_enqueue_style('csf-happy-booking-widget');


function insert_booking_widget()

$content = "<div class="bookingWidget">";
$content .= "<h2>Book Now</h2>";
$content .= "<form method="get" action="https://mattarahkka.happybooking.io/">";
$content .= "<table class="sideTable"><tbody><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-in</span>";
$content .= "<input id="from" name="from" class="checkInsDate" type="text">";
$content .= "</tr><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-out</span>";
$content .= "<input id="to" name="to" class="checkInsDate" type="text">";
$content .= "</tr></tbody></table>";
$content .= "<div class="buttonHolder">";
$content .= "<input class="btn" value="Search available lodgings" type="submit">";
$content .= "</div>";
$content .= "<input type="hidden" name="lang" value="English"/>";
$content .= "</form></div>";

return $content;

add_shortcode('happy-booking-widget','insert_booking_widget');

add_action('wp_enqueue_scripts', 'csf_booking_widget_custom_jquery');


The Js file (datepicker_2):



jQuery(function() 
var dates = jQuery("#from, #to").datepicker(
showWeek: true,
firstDay: 1,
dateFormat: 'yy-mm-dd',
dayNamesMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
weekHeader: "W.",
monthNames: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
onSelect: function(selectedDate)
jQuery.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not(this).datepicker("option", option, date);
autoclose: true;


);
);









share|improve this question













I know this question have been up for a few years ago, but I could not find relevant answer to my problem.



I have made a booking widget plug in seen on the middle on this WP page:
http://mattarahkka.com/the-lodge/#



Afte a date is selected the page scrolls to the top. The date picker remains open and the date remains selected. But why does the page jump to the top?



widget php code:



// include custom jQuery
functieon csf_booking_widget_custom_jquery()

/* REGISTER JS FOR PLUGIN */
wp_register_script('datepicker',plugins_url().'/csf-booking-widget/js/datepicker_2.js');
/* REGISTER CSS FOR PLUGIN */
wp_register_style('jquery-ui','http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css');
wp_register_style('csf-happy-booking-widget',plugins_url().'/csf-booking-widget/css/happy-booking-widget.css');
/* CALL ALL JS FOR PLUGIN */
wp_enqueue_script('jXquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_script('datepicker');
/* CALL ALL CSS FOR PLUGIN */
wp_enqueue_style('jquery-ui');
wp_enqueue_style('csf-happy-booking-widget');


function insert_booking_widget()

$content = "<div class="bookingWidget">";
$content .= "<h2>Book Now</h2>";
$content .= "<form method="get" action="https://mattarahkka.happybooking.io/">";
$content .= "<table class="sideTable"><tbody><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-in</span>";
$content .= "<input id="from" name="from" class="checkInsDate" type="text">";
$content .= "</tr><tr>";
$content .= "<span class="date-title" style="padding: 0px">Check-out</span>";
$content .= "<input id="to" name="to" class="checkInsDate" type="text">";
$content .= "</tr></tbody></table>";
$content .= "<div class="buttonHolder">";
$content .= "<input class="btn" value="Search available lodgings" type="submit">";
$content .= "</div>";
$content .= "<input type="hidden" name="lang" value="English"/>";
$content .= "</form></div>";

return $content;

add_shortcode('happy-booking-widget','insert_booking_widget');

add_action('wp_enqueue_scripts', 'csf_booking_widget_custom_jquery');


The Js file (datepicker_2):



jQuery(function() 
var dates = jQuery("#from, #to").datepicker(
showWeek: true,
firstDay: 1,
dateFormat: 'yy-mm-dd',
dayNamesMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
weekHeader: "W.",
monthNames: ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],
onSelect: function(selectedDate)
jQuery.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not(this).datepicker("option", option, date);
autoclose: true;


);
);






jquery wordpress datepicker jquery-ui-datepicker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 14:18









Pegasuz73

83




83











  • Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
    – Jamie_D
    Nov 11 at 15:27










  • Thank you. Now it is working as intended
    – Pegasuz73
    Nov 11 at 20:57
















  • Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
    – Jamie_D
    Nov 11 at 15:27










  • Thank you. Now it is working as intended
    – Pegasuz73
    Nov 11 at 20:57















Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
– Jamie_D
Nov 11 at 15:27




Try adding the following to your onSelect function" $('#ui-datepicker-div table td a').attr('href', 'javascript:;');
– Jamie_D
Nov 11 at 15:27












Thank you. Now it is working as intended
– Pegasuz73
Nov 11 at 20:57




Thank you. Now it is working as intended
– Pegasuz73
Nov 11 at 20:57

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239844%2fjquery-datepicker-scrolls-to-top-of-page-after-date-selected%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239844%2fjquery-datepicker-scrolls-to-top-of-page-after-date-selected%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

What does pagestruct do in Eviews?

Dutch intervention in Lombok and Karangasem

Channel Islands