I have 2 Dropdownlist and I want to call this Javascript function in ASP.Net using my dropdownlist ID.how can I get this value, The javascript function is disabling the selected item from the ddlHidden1 so it cannot be selected to ddlHidden2 the same as ddlHidden1 you cannot select the selected item in the ddHidden2…
…this the .aspx
<asp:DropDownList ID = "ddlHidden1" runat="server" >
<asp:ListItem value="0">Select</asp:ListItem>
<asp:ListItem value="1">1</asp:ListItem>
<asp:ListItem value="2">2</asp:ListItem>
<asp:ListItem value="3">3</asp:ListItem>
<asp:ListItem value="4">4</asp:ListItem>
<asp:ListItem value="5">5</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID = "ddlHidden2" runat="server">
<asp:ListItem value="0">Select</asp:ListItem>
<asp:ListItem value="1">1</asp:ListItem>
<asp:ListItem value="2">2</asp:ListItem>
<asp:ListItem value="3">3</asp:ListItem>
<asp:ListItem value="4">4</asp:ListItem>
<asp:ListItem value="5">5</asp:ListItem>
</asp:DropDownList>
…this the script tag that I get from the internet I’ve paste my dropdownlist ID in here it is working but’ if I save the value to database it resets, I think I’m not calling the DropDownlist ID in the right way can someone help me. on how to call the ID in the asp.net way, thank you.
<script type=text/javascript>
var ids = ['ddlHidden1', 'ddlHidden2'];
NodeList.prototype.forEach = HTMLCollection.prototype.forEach =
Array.prototype.forEach;
var selected = [];
ids = makeid(ids);
var opts = find(ids);
updateS(opts);
massdisabler(opts);
assignFunc(ids, disabler);
function assignFunc(i, func) { //done
var x;
for (x = 0; x < i.length; ++x) {
i[x].onchange = function () {
func(this);
};
}
}
function disabler(i) {
console.log(selected);
updateS(opts);
massdisabler(opts);
}
function makeid(i) { //done
var o = [];
i.forEach(function (v) {
o.push(document.getElementById(v))
});
return o;
}
function find(ids) { //done
var o = {};
for (var i = 0; i < ids.length; ++i) {
o[i] = {};
ids[i].children.forEach(function (v, n) {
o[i][n] = v;
});
}
return o;
}
function massdisabler(op) { //done
var y = Object.keys(op).length;
for (var x = 0; x < y; x++) {
var t = 0,
l = Object.keys(opts[x]).length;
for (var v = 0; v < l; v++) {
t = op[x][v];
if (selected.some(function (k) {
if (t.value == k) {
return true;
}
})) {
t.setAttribute("disabled", "disabled");
} else {
t.removeAttribute("disabled");
}
}
}
}
function updateS(op) { //done
var s = [],
y = Object.keys(op).length;
for (var x = 0; x < y; x++) {
var t = 0,
l = Object.keys(opts[x]).length;
for (var v = 0; v < l; v++) {
t = op[x][v];
var yn = s.some(function (k) {
if (t.value == k) {
return true;
}
});
if (t.selected && (!yn)) s.push(t.value);
}
}
selected = s;
}
</script>