<head>
<title>How to
get
DropDownList value based on text/value
in
jQuery</title>
<script src=
"Scripts/jquery-1.11.1.min.js"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
function
SetDropDownByText() {
var
selectedText =
'Admin'
;
$(
'#ddlRole option'
).map(
function
() {
if
($(
this
).text() == selectedText)
return
this
;
}).attr(
'selected'
,
'selected'
);
}
function
SetDropDownByValue() {
var
selectedValue =
'3'
;
$(
'#ddlRole option'
).map(
function
() {
if
($(
this
).val() == selectedValue)
return
this
;
}).attr(
'selected'
,
'selected'
);
}
</script>
</head>
<body>
<div>
<select id=
"ddlRole"
>
<option value=
"-1"
>Select</option>
<option value=
"1"
>User</option>
<option value=
"2"
>Admin</option>
<option value=
"3"
>Super Admin</option>
</select>
<input type=
"button"
value=
"Set By Text"
onclick=
"SetDropDownByText()"
/>
<input type=
"button"
value=
"Set By Value"
onclick=
"SetDropDownByValue()"
/>
</div>
</body>
</html>