ghornet
03-28-2003, 06:21 PM
I have 'borrowed' the following code (: But it is doing something that I don't know how to fix, basically all I am trying to do is alert up the different options that somebody has choosen from a select box, but when I run the following code nothing happens the first time, but the next time I click on something it gives me the value from the first time I clicked, or also the line that is commented out //alert(opt.length); if I uncomment that it works just fine. I am sure that it is a problem with a variable not being set right... anyone have any ideas?
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
if (opt[intLoop].selected)
{
index = selected.length;
selected[index] = new Object;
selected[index].value = opt[intLoop].value;
selected[index].index = intLoop;
}
}
return selected;
}
function class_onclick()
{
opt = document.all['SelectClass'].options;
//alert(opt.length);
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
strSel += sel[item].value + "\n";
alert("Selected Items:\n" + strSel);
}
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
if (opt[intLoop].selected)
{
index = selected.length;
selected[index] = new Object;
selected[index].value = opt[intLoop].value;
selected[index].index = intLoop;
}
}
return selected;
}
function class_onclick()
{
opt = document.all['SelectClass'].options;
//alert(opt.length);
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
strSel += sel[item].value + "\n";
alert("Selected Items:\n" + strSel);
}