my combo box id is combo1, i want to clear the values that are loaded in combo box from database, plz help me with sample code..
how to clear the combo box values using javascript..?
Collapse
X
-
Tags: None
-
//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlH ttp.statusText;//records to load combo..
strArrRow =strDetails.spl it('|');
var x=document.getE lementById("com bo1");
for (intLoop=0;intL oop<strArrRow.l ength-1;intLoop++)
{
var y=document.crea teElement('opti on');
y.text=strArrRo w[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}Comment
-
Originally posted by nirmalsingh//my coding...
var strDetails;
var intLoop;
var strArrRow = new Array();
strDetails=xmlH ttp.statusText;//records to load combo..
strArrRow =strDetails.spl it('|');
var x=document.getE lementById("com bo1");
for (intLoop=0;intL oop<strArrRow.l ength-1;intLoop++)
{
var y=document.crea teElement('opti on');
y.text=strArrRo w[intLoop]
try
{
x.add(y, null);
}
catch(ex)
{
x.add(y);
}
}Comment
-
sorry to make u confused sir, i want to clear the options from the select box. not from database.Comment
-
Originally posted by r035198xWell the general rule is if you have a select by the name box, then
To clear all options of box just do
box.options.len gth = 0;Comment
-
Originally posted by b1randonThis is by far the best way to remove the options. If you try to remove them one by one in a loop you won't be able to remove the last option. I lost a good bit of hair before realizing that options.length= 0; is all I needed :/Comment
Comment