Description:
Sometime we have requirement like remove dropdown list items/option when something occur like for example if we select category is equals to vegetable then only vegetable are shown in other dropdown and other items of dropdown list will be removed.
So below is the example that demonstrates to remove/delete item in dropdown list using client side script like jQuery or JavaScript.
Code:
In this example we explain that how to delete selected
item from dropdown list using JavaScript/jQuery in asp.net.or how to remove
selected item from dropdown list using JavaScript or jQuery in asp.net.
Sometime we have requirement like remove dropdown list items/option when something occur like for example if we select category is equals to vegetable then only vegetable are shown in other dropdown and other items of dropdown list will be removed.
So below is the example that demonstrates to remove/delete item in dropdown list using client side script like jQuery or JavaScript.
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/D TD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/ xhtml">
<head runat="server">
<title>Delete (Remove) selected Item (Option) from DropDownList using JavaScript and jQuery</title>
</head>
<body>
<form id="form1" runat="server">
<fieldset>
<legend>Javascript</legend>
<select id="ddlCountry" style="width: 150px;">
<option value="1">India</option>
<option value="2">Pakistan</option>
<option value="3">USA</option>
<option value="4">UK</option>
</select>
<br />
<hr />
<input type="button" id="btnDelete" value="Delete" onclick="DeleteValues();"/>
</fieldset>
<script type="text/javascript">
function DeleteValues() {
var dropDown = document.getElementById("ddlCo untry");
for (var i = 0; i <= dropDown.options.length; i++) {
if (dropDown.options[i].selected) {
alert(dropDown.options[i].text + " is removed from dropdownlist");
dropDown.removeChild(dropDown. options[i]);
break;
}
}
}
</script>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/D
<html xmlns="http://www.w3.org/1999/
<head runat="server">
<title>Delete (Remove) selected Item (Option) from DropDownList using JavaScript and jQuery</title>
</head>
<body>
<form id="form1" runat="server">
<fieldset>
<legend>Javascript</legend>
<select id="ddlCountry" style="width: 150px;">
<option value="1">India</option>
<option value="2">Pakistan</option>
<option value="3">USA</option>
<option value="4">UK</option>
</select>
<br />
<hr />
<input type="button" id="btnDelete" value="Delete" onclick="DeleteValues();"/>
</fieldset>
<script type="text/javascript">
function DeleteValues() {
var dropDown = document.getElementById("ddlCo
for (var i = 0; i <= dropDown.options.length; i++) {
if (dropDown.options[i].selected) {
alert(dropDown.options[i].text + " is removed from dropdownlist");
dropDown.removeChild(dropDown.
break;
}
}
}
</script>
</form>
</body>
</html>
0 comments:
Post a Comment