View Full Version : multiple values
alison
03-06-2003, 08:41 PM
Hi, I am trying to create a script that allows users to select from three different combo boxes. The second and third combo box values are NOT dependent on the value selected in the first.
When all three boxes have had a value selected I want the user to be directed to a specific URL, dependent on the values of the options he chose.
Is this do-able? I am about to go mad (or go and buy a large case of beer) as I have spent ages trying.
Any help tremendously appreciated.
Alison
cheesebagpipe
03-06-2003, 10:09 PM
Could you post a sample of some typical option values and the urls you'd like them mapped to...you'll generally get a more detailed answer the more specific you make the description...
Jason
03-06-2003, 10:25 PM
It seems doable, Im not entirely sure...here are some links to another thread with similar problems
http://www.codingforums.com/showthread.php?s=&threadid=11998&highlight=combo
Jason
alison
03-06-2003, 11:27 PM
Sure! The first combo box has values of
3 mins
5 mins
10 mins
The second has values of
Stressed
Happy
Bored
The third has
Active
Semi-active
Passive
(it is a media selector by the way which picks media items (flash movies) embedded in web pages)
The url's they are going to are irrelevant at the mo (i.e not finished!!) It is passing the variables that is confusing me...
Thanks a lot.
Alison
cheesebagpipe
03-07-2003, 12:03 AM
Here's one approach:
Put all three drop-downs in the same form; set them as illustrated below. When the user changes any select, Select.onchange is called, invoking chkredir(), and passing references to all three Select objects.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">
// redirect URLS here, keyed to combinations of selected indexes
var URLs = Object();
URLs['111'] = 'http://www.google.com';
URLs['211'] = 'http://www.altavista.com';
URLs['311'] = 'http://www.hotbot.com';
function chkredir(oSelect1,oSelect2,oSelect3) {
var sOpts;
var s1idx = oSelect1.selectedIndex;
var s2idx = oSelect2.selectedIndex;
var s3idx = oSelect3.selectedIndex;
if (!s1idx || !s2idx || !s3idx) return false;
else sOpts = String(s1idx) + String(s2idx) + String(s3idx);
alert(oSelect1[s1idx].value + '\n' + oSelect2[s2idx].value + '\n' + oSelect3[s3idx].value); //demo
if (URLs[sOpts]) frames['movies'].location = URLs[sOpts];
}
</script>
</head>
<body>
<div align="center">
<form>
<select name="Attention" onchange="chkredir(this,Mood,Motivation)">
<option>Attention Span</option>
<option value="3 mins">3 mins</option>
<option value="5 mins">5 mins</option>
<option value="10 mins">10 mins</option>
</select>
<select name="Mood" onchange="chkredir(Attention,this,Motivation)">
<option>Mood</option>
<option value="Stressed">Stressed</option>
<option value="Happy">Happy</option>
<option value="Bored">Bored</option>
</select>
<select name="Motivation" onchange="chkredir(Attention,Mood,this)">
<option>Motivation</option>
<option value="Active">Active</option>
<option value="Semi-active">Semi-active</option>
<option value="Passive">Passive</option>
</select>
</form>
<iframe name="movies" width="700" height="400"></iframe>
</div>
</body>
</html>
The function gets the selectedIndex property - the integer representing which option has been selected (JS counts from 0, so the 'dummy' options are all option 0). It checks to see if any of them is zero - zero is synonymous with false in JS so, the not operator (!) 'flips' any 0 to true and the function terminates. Otherwise, we're good to go; the next line is a demo (remove it); all that's left is to check for a URL (stored as a property of the URLs object) and load it if found. I used an iframe, typical for swfs; change to simply location = if you want to redirect the entire window.
Hope it works! cbp
alison
03-09-2003, 09:34 AM
Sorry for the late reply- I've been away for the weekend- thank you SO much for the code- I haven't tried it yet but I will do so now. Am eternally grateful and would buy you a virtual pint if technology allowed!
Alison
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.