Datepicker range show "to" when select a date on "from"

Datepicker range show "to" when select a date on "from"

Hi, i'm using a example of datepicker range.

I'm trying show the datepicker "to" when the user select a date from a "from" datepicker.

For this I'm subscribing to the method of the datepicker onSelect "from" to make a show in datepicker "to".

I am using the following code:
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Datepicker - Select a Date Range</title>
  6. <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
  7. <script src="../../jquery-1.8.0.js"></script>
  8. <script src="../../ui/jquery.ui.core.js"></script>
  9. <script src="../../ui/jquery.ui.widget.js"></script>
  10. <script src="../../ui/jquery.ui.datepicker.js"></script>
  11. <link rel="stylesheet" href="../demos.css">
  12. <script>
  13. $(function() {
  14. $( "#from" ).datepicker({
  15. defaultDate: "+1w",
  16. changeMonth: true,
  17. numberOfMonths: 3,
  18. onSelect: function( selectedDate ) {
  19. $( "#to" ).datepicker( "option", "minDate", selectedDate );
  20. test();
  21. }
  22. });
  23. $( "#to" ).datepicker({
  24. defaultDate: "+1w",
  25. changeMonth: true,
  26. numberOfMonths: 3,
  27. onSelect: function( selectedDate ) {
  28. $( "#from" ).datepicker( "option", "maxDate", selectedDate );
  29. }
  30. });
  31. });
  32. function test() {
  33. $( "#to" ).datepicker( "show" );
  34. }
  35. </script>
  36. </head>
  37. <body>

  38. <div class="demo">

  39. <label for="from">From</label>
  40. <input type="text" id="from" name="from"/>
  41. <label for="to">to</label>
  42. <input type="text" id="to" name="to"/>
  43. <input type="button" id="bt" value="ok" onclick="javascript: test();" />
  44. </div><!-- End demo -->

  45. <div class="demo-description">
  46. <p>Select the date range to search for.</p>
  47. </div><!-- End demo-description -->

  48. </body>
  49. </html>

When testing this code, when I click on the date "from" then the calendar "to" is displayed and rapidly disappears.

The curious thing is that if I'm in chrome for example, when you click another tab and then return to the calendar tab for example "to" is displayed correctly.

The example also has an "ok" button. Running the same code, in this case the method "test" and clicking this button calendar "to" is displayed correctly.

I'm working on this problem for a long time and have tried various ways to display calendar "to" But I always get the same result.

Thanks for reading my problem, if somehow I was not clear please question me so I can better clarify.