Wednesday 6 January 2021

MVC - JavaScript - jQuery - How to clear drop down list using javascript

 

 Watch this example on YouTube


 

 @using (Html.BeginForm("Index", "Home"))
{
    @Html.DropDownListFor(x=>x.or.ProductID, new SelectList(Model.prod,"ProductID", "Name"), new { @id = "myID" })

    
}
<input type="submit" onclick="DoSomething()" value="Clear Drop Down List" />

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

         function DoSomething(){
            $("#myID").empty();
        }
    </script>
    }

No comments:

Post a Comment