Bill Greer
Bill Greer

Reputation: 3166

I'm having trouble changing a select list selected value

I have a select list with an id of SelectedEmployee. I have a on change event in jquery where I successfully get the value of the selected item:

        $("#SelectedEmployee").change(function () {
            selectedEmployee = $("#SelectedEmployee").val();
            $("div.myDropDownDiv select").val(selectedEmployee.toString());
            alert(selectedEmployee);          
            myCal.fullCalendar('refetchEvents');            
         });

My alert returns the value of the selected employee but the DOM still thinks the previous selection is the selected employee. I have tried both the following within the change event with no luck.

$("div.myDropDownDiv select").val(selectedEmployee.toString());


$('#SelectedEmployee option[value=' + selectedEmployee + ']').prop('selected', true)

Upvotes: 0

Views: 47

Answers (1)

Leandro Soares
Leandro Soares

Reputation: 2972

The first example you gave

$("div.myDropDownDiv select").val(selectedEmployee.toString());

should work...

Here is a Working Example

Maybe you should check if selectedEmployee.toString() is returning the correct value.

Or even if the select is inside a div which has the class myDropDownDiv. Maybe, myDropDownDiv is an id instead of class

Upvotes: 1

Related Questions