locked
datepicker on button click not working RRS feed

  • Question

  • User-1579656392 posted
         <script>
    
               $(document).ready(function () {
                   $('#Submit').click(function () {                  
                       var eventDates = "2021-01-21|2021-02-05";
                       var xArrayFechas = eventDates.split('|');
                       var xDates = {};
                       for (var i = 0; i < xArrayFechas.length; i++) {
                           xDates[new Date(xArrayFechas[i])] = true;
                           alert(xArrayFechas[i]);
                       }
                    
                           $("#datepicker").datepicker({
                              
                               beforeShowDay: function (date) {
                                   var wdate = date;
                                   if ($.inArray(wdate, xArrayFechas) >= 0) {
                                       return [false];
                                   }
                                   return [true];
                               }
                           });
                   
                           $("#datepicker").datepicker("refresh");
    
    
                   })
               })
    
    
    
                </script>


    Can anyone please help? It works on page load but not on button click. I was trying to block more dates on button click based on different parameters.

    <script> $(document).ready(function () { $('#Submit').click(function () { var eventDates = "2021-01-21|2021-02-05"; var xArrayFechas = eventDates.split('|'); var xDates = {}; for (var i = 0; i < xArrayFechas.length; i++) { xDates[new Date(xArrayFechas[i])] = true; alert(xArrayFechas[i]); } $("#datepicker").datepicker({ beforeShowDay: function (date) { var wdate = date; if ($.inArray(wdate, xArrayFechas) >= 0) { return [false]; } return [true]; } }); $("#datepicker").datepicker("refresh"); }) }) </script>

    Thursday, December 17, 2020 5:54 PM

All replies

  • User475983607 posted

    Are you trying to change the date picker configuration dynamically?  Is there anyway you can explain the application flow, expected results, and all the relevant code?  Is #Submit a submit button?

    Thursday, December 17, 2020 6:19 PM
  • User1535942433 posted

    Hi SuchiSayami,

    It works on page load but not on button click. I was trying to block more dates on button click based on different parameters.

    Could you tell us what is your "submit" button?Is it a submit button?

    I suggest you could try this:

    $(document).on("click", "#Submit", function (e){
     e.preventDefault();
    })

    Best regards,

    Yijing Sun

    Friday, December 18, 2020 2:22 AM