Html Reload Dropdown Value Javascript
I Have a script like this:
Solution 1:
Its already answered here
functionbindDdl() {
try {
var ddl = document.getElementById('ddl1');
var x = PageMethods.GetData('', onsuccess, onfail);
}
catch (e) {
alert(e);
}
}
functiononsuccess(result) {
try {
var ddl = document.getElementById('ddl1');
var count= ddl.options.length;
while (ddl.options.length > 0) {
ddl.options.remove(0);
}
for (var i = 0; i < result.length-1; i=i+2) {
var opt = document.createElement("option");
// Assign text and value to Option object
opt.text = result[i];
opt.value = result[i+1];
ddl.options.add(opt);
}
}
catch (e) {
alert(e);
}
}
You can have the onchange event like this
So you can reload it but
NOTE :- if you are binding server side controls at client side it will always give you an error Instead bind them on server side and add values at client side its preferable
Solution 2:
You can try something similar to :
functionreload() {
var two = document.getElementById('second');
// clear the select with id="two"
two.innerHTML = "";
// re-add the optionsvar words = newArray("One", "Two", "Three", "Four" ... ); // fill it up yourselffor(var i = 1; i <= 9; i++) {
var option = document.createElement("option");
option.text = words[i-1];
option.value = i;
two.appendChild(option);
}
}
Post a Comment for "Html Reload Dropdown Value Javascript"