...

View Full Version : :: using multiple select boxes and javascript ::



babelfish
07-17-2003, 02:49 PM
atm im using a few select boxes that are created dynamically for part of a corporate wan.

<select name="projectFileLocation">
<option value="" selected></option>
<option value="Boston">Boston</option>
<option value="Inverness">Inverness</option>
<option value="Lincoln">Lincoln</option>
<option value="Swinderby">Swinderby</option>
</select>

now, on some of these menus i want the user to be able to select multiple values so i added the 'multiple' in the tag - that allows me to select more than 1 - problem is i am using a javascript method to create a url from the selected options on the page - this then creates a search

basically i wanna know how to get the multiple values from the multiple select as form.element.value dont work - it just gets the 1st one

thanks!

(cant show the page as its hosted internally and contains sensitive info)

requestcode
07-17-2003, 04:40 PM
Maybe this will help:
<html>
<head>
<title>Drop Down TEst</title>
<script language="JavaScript">
function disp(frmobj)
{
len=frmobj.mysel.length
myval=""
for(i=0;i<len;i++)
{
if(frmobj.mysel.options[i].selected)
{myval+=frmobj.mysel.options[i].value}
}
alert(myval)
}
</script>
</head>
<body>
<form name="myform">
<select name="mysel" multiple>
<option value="some value 1">Click Me</option>
<option value="some value 2">Click Me</option>
<option value="some value 3">Click Me</option>
<option value="some value 4">Click Me</option>
</select>
<input type="button" value="Click Me" onClick="disp(this.form)">
</form>
</body>
</html>

babelfish
07-17-2003, 04:43 PM
thanks - got tied up doing other stuff 2day now - will lookk tomorrow - i assume this will work with a few select boxes on the same page as i have about 6 that are used to build the custom search

requestcode
07-17-2003, 05:32 PM
As writen it will only work with the one select. I will see what I can do to modify so that it will work with more that one and post the code here.

requestcode
07-17-2003, 05:39 PM
Here is the code modified to work with more than one select:
<html>
<head>
<title>Drop Down TEst</title>
<script language="JavaScript">
function disp(frmobj)
{
len=frmobj.length
myval=""
for(i=0;i<len;i++)
{
if(frmobj.options[i].selected)
{myval+=frmobj.options[i].value}
}
alert(myval)
}
</script>
</head>
<body>
<form name="myform">
<select name="mysela" multiple>
<option value="some value 1">Click Me</option>
<option value="some value 2">Click Me</option>
<option value="some value 3">Click Me</option>
<option value="some value 4">Click Me</option>
</select>
<input type="button" value="Click Me" onClick="disp(document.myform.mysela)">
<select name="myselb" multiple>
<option value="some value 1">Click Me</option>
<option value="some value 2">Click Me</option>
<option value="some value 3">Click Me</option>
<option value="some value 4">Click Me</option>
</select>
<input type="button" value="Click Me" onClick="disp(document.myform.myselb)">
</form>
</body>
</html>

babelfish
07-18-2003, 08:38 AM
thanks m8 - will try and get a look at it today



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum