Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple select boxes

Status
Not open for further replies.

cajchris

Programmer
Oct 13, 2005
57
GB
when I am using a multiple select box it is workin ok for a single selection, but not for many selections.

Here is my code for it:

<select name="searchedDirectoryNames" id="selectedDirectories" size = "2" class="normalSelect" multiple>

<option value="About Us">About Us</option>
<option value="News">News</option>
<option value="Registrants">Registrants</option>

</select>

when i select About US, News, and Registrants in that order using the ctrl key it is being interpreted as only About Us being Selected.

even more strangely when i select News, Registrants and then About Us, it is still being interpreted as About Us. so it seems it is taking the top one only in the multiple select case.

i was told on the html forum that i required javascript. would any1 be able to post some example script that would get these multiple values. I take it the values would be in the form of some comma seperated list.

the variable searchDirectoryNames needs to contain the values selected as this is then interpreted by my search engine to determine which directories to search on

any ideas?

thanks
cajchris
 
If you want to pick up on all values server-side (i.e. AFTER the form has been submitted), then you would use whatever server-side language you normally use. No client-side JavaScript is required.

If you want to do somethiing with the values client-side, then you'd need to explain what you want to do with them (or how you want them) before help can be given. Saying "I take it the values would be in the form of some comma seperated list." implies you don't actually know yourself how you want the values... so how about YOU tell US how you want them?

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I do not have different opinion. But, if you just want to see client-side what server-side would see before submitting, it is very easy.
[tt]
var s="";
var elem=document.getElementById("selectedDirectories");
for (var i=0;i<elem.length;i++) {
s+=(s=="")?elem.options.value:","+elem.options.value;
}
//alert(s); //to display
[/tt]
If it appears in some kind of handler, elem may be simplified depending on the concrete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top