Click to See Complete Forum and Search --> : Value of Select Box


jason
12-08-2002, 11:55 PM
I am trying to get the value of a select box (set to multiple).

I have tried:
document.all.FormName.FormField.selected.value
AND
document.all.FormName.FormField.value

But neither seem to work. Basically what I am trying to do is use a Javascript funtion to submit a go to another page (using location.href('....')), with the value of a select box appended to the url as a url variable, but I just keep getting an error "Object doesn't support this property of method".

function down(){
location.href('index.cfm?report=repname&parent='document.all.FormName.FormField.selected.value);
return true;
}


Thanks in adance.

gil davis
12-09-2002, 05:23 AM
For a multiple select, you will have to step through each option and test it's selected attribute.

var st = "";
var sl = document.formName.selectName.options;
for (var i in sl)
{if (sl[i].selected)
{st = (st == "") ? sl[i].value : " " + sl[i].value;}
}

themangler
12-09-2002, 12:53 PM
The following code will allow you to retrieve the value that is currently in the select drop-down field. It works in both IE and Netscape.

document.formName.selectName.options[document.formName.selectName.selectedIndex].value

(The formName and selectName in the code above should be change to your form and control names - leave 'selectedIndex' as it is.)

That should do the job for ya!

sampson