Louie Miranda
Louie Miranda

Reputation: 1159

Could not get proper select value from jquery and pass it to date picker

I am trying to get a select value using jquery, but when debugging. It only shows the first value == 1.

Any idea why? Here's my code.

var clinic = $("#AppointmentClinicId").val();

 $("#datepicker").datepicker({
    dateFormat: "yy-mm-dd",
    minDate: 0,
    numberOfMonths: 3,
    showButtonPanel: true,
    beforeShowDay: function(date) {
        var day = date.getDay();

        console.log("clinic:" + clinic);

        if (clinic == 1) {
            return [day == 1, ""];
        }

        if (clinic == 2) {
            return [day == 2, ""];
        }

        if (clinic == 3) {
            return [day == 3, ""];
        }

        if (clinic == 4) {
            return [day == 4, ""];
        }

        if (clinic == 5) {
            return [day == 5, ""];
        }

        if (clinic == 6) {
            return [day == 6, ""];
        }

    }
 }).val()

Basically, I just want to return specific open days depending on the clinic. The thing is, I could not get the current value from #AppointmentClinicId.

Help!

Upvotes: 0

Views: 80

Answers (1)

Anoop
Anoop

Reputation: 23208

You are not reading latest value of AppointmentClinicId. You should read from dom every time. Move line clinic = $("#AppointmentClinicId").val(); inside beforeShowDay

....

beforeShowDay: function(date) {
        var day = date.getDay(),
         clinic = $("#AppointmentClinicId").val();
...

Upvotes: 1

Related Questions