0

I was wondering if anyone could advise me a little. I am attempting to use JQuery to select my dropdown item by a given value. Here is what I have

var myVar = document.getElementById('<%= hiddenID.ClientID %>').value

    if (myVar != "") {
        var val = $("select[name*=drpDescription] option").filter(function () {
            return ($(this).val() == myVar)
        });

        $("select[name*=drpDescription]").val(val.val());
    }

The above code snippet does get the correct option based on it's value matching my hiddenfield value. What I can't do is get my dropdown to display it as the selected item. I wondered if anoyone has any advise on where I am slightly missing the point.

Thank you for any help.

user3036965
  • 155
  • 2
  • 18

1 Answers1

0

You can set the value by passing it as parameter in .val() with select elements selector:

$("select[name*=drpDescription]").val(myVar);
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125