samedi 27 juin 2015

Javascript show select box based on output

I want to have a select box that shows the available hours on the day based on the date selected. I've made the code that does that but it shows both select boxes when someone changes the date. Need to set it up so it doesn't shows only the select box for the date. http://ift.tt/1HnN39V here's the code.

    <script type="text/javascript">
        $('#date').change(function(){
            var test = $("#date").val();
            if (test) {
                $('#time').each(function(){
                $(this).addClass('hidden');
                });
                test = '.'+test.replace('/','_');
                test = test.replace('/','_');
                $(test).removeClass('hidden');
            };
        });



        // When the document is ready
                var availableDates = ["9-6-2015","14-6-2015","15-6-2015"];

    function available(date) {
      dmy = date.getDate() + "-" + (date.getMonth()+1) + "-" + date.getFullYear();
      if ($.inArray(dmy, availableDates) != -1) {
        return [true, "","Available"];
      } else {
        return [false,"","unAvailable"];
      }
    }

    $('#date').datepicker({ beforeShowDay: available });


    </script>

Aucun commentaire:

Enregistrer un commentaire