Saturday, 30 April 2016

MVC - Javascript - Select item in select list (dropdownlist) by text

Watch this example on YouTube


<select id="ddlID">
    <option value="0">blue</option>
    <option value="0">yellow</option>
    <option value="0">green</option>
</select>

@section Scripts{
<script type="text/javascript">

        $("#ddlID option").filter(function () {
            return $(this).text().trim() == "yellow";
        }).prop('selected', true);

</script>
}

No comments:

Post a Comment