Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2003, 02:49 PM   PM User | #1
babelfish
Regular Coder

 
Join Date: Jun 2002
Location: England =)
Posts: 518
Thanks: 25
Thanked 0 Times in 0 Posts
babelfish can only hope to improve
:: using multiple select boxes and javascript ::

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)
__________________
"They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson
babelfish is offline   Reply With Quote
Old 07-17-2003, 04:40 PM   PM User | #2
requestcode
Regular Coder

 
Join Date: Jun 2002
Posts: 626
Thanks: 0
Thanked 0 Times in 0 Posts
requestcode is an unknown quantity at this point
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>
requestcode is offline   Reply With Quote
Old 07-17-2003, 04:43 PM   PM User | #3
babelfish
Regular Coder

 
Join Date: Jun 2002
Location: England =)
Posts: 518
Thanks: 25
Thanked 0 Times in 0 Posts
babelfish can only hope to improve
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
__________________
"They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson
babelfish is offline   Reply With Quote
Old 07-17-2003, 05:32 PM   PM User | #4
requestcode
Regular Coder

 
Join Date: Jun 2002
Posts: 626
Thanks: 0
Thanked 0 Times in 0 Posts
requestcode is an unknown quantity at this point
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 is offline   Reply With Quote
Old 07-17-2003, 05:39 PM   PM User | #5
requestcode
Regular Coder

 
Join Date: Jun 2002
Posts: 626
Thanks: 0
Thanked 0 Times in 0 Posts
requestcode is an unknown quantity at this point
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>
requestcode is offline   Reply With Quote
Old 07-18-2003, 08:38 AM   PM User | #6
babelfish
Regular Coder

 
Join Date: Jun 2002
Location: England =)
Posts: 518
Thanks: 25
Thanked 0 Times in 0 Posts
babelfish can only hope to improve
thanks m8 - will try and get a look at it today
__________________
"They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson
babelfish is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19 PM.


Advertisement
Log in to turn off these ads.