...

View Full Version : combo boxes



mikedean
07-26-2002, 11:28 AM
Been tryin the double combo box script with *some* success but havin difficulty with two things. First I want to abandon the GO button entirely and have the second field directly link to the URL without having to click - how'd'I do that?
Second, some of my links from the *first* combo box have only a single option, and currently have single new option in the second field with CLICK GO in it - not very pretty, so how can I make selected options from first box simply not bother with the second one and just go straight to the URL?
Does that make sense?
Mike:) :p

ShriekForth
07-26-2002, 04:18 PM
Using the onChange funtion of the second select box will allow you to call a function and then go to the url.

<select name="category" onChange="setSubCategory()">

As for having it go if there is only 1 and 1, you can check to see how long the options list is, and then check the length of the second select box to be equal to 1 as well.

document.childForm.category.length

ShriekForth

mikedean
07-26-2002, 04:25 PM
ummmm, pardon?
i didnt get a bleedin' word of that :rolleyes:
mike:thumbsup:

RadarBob
07-26-2002, 05:03 PM
What the programmer said was...

Let's say you have this:


<select name="gohere" ... onChange="GoForth (this)>
Where do you want to go?
<option value="http://www.radarbob.com">
RadarBob web site</option>
<option value="http://www.apple.com">
Apple web site</option>
</select>





function GoForth (whereIwantToGo) {
for (var i=0; i<whereIwantToGo.length; i++) {

if (whereIwantToGo.options[i].selected) {
window.location= whereIwantToGo.options[i].value;
}
}
} // function GoForth()

mikedean
07-26-2002, 05:08 PM
anyone here an interpreter? im sorry guys - Ive no doubt youve both given me perfect solutions, but you may as well be speaking ancient greek for all Im getting from it. Could either of you post an actual example which I could cut and paste and figure out from there?
Sorry to be such a halfwit
Mike

RadarBob
07-26-2002, 07:03 PM
Ask and ye shall receive:
Here is a complete, working :) HTML page. When you select from the drop down list you are taken immediately (w/out a pesky GO button to click) to that web site.

I added one tweak from my code above. the first <option> in the list is a prompt to select from the list. Otherwise, in short, it wouldn't work so good.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>

<script language="JavaScript" type="text/javascript">
<!--
function GoForth (whereIwantToGo) {
for (var i=0; i<whereIwantToGo.length; i++) {

if (whereIwantToGo.options[i].selected) {
window.location= whereIwantToGo.options[i].value;
}
}
} // function GoForth()
//-->
</script>
</head>


<body>
<form>
<b>Where do you want to go?</b><br>
<select name="gohere" onChange="GoForth(this)">
<option value="" SELECTED>Select a site from this list</option>
<option value="http://www.hp.com">
hewlet Packard web site</option>
<option value="http://www.apple.com">
Apple web site</option>
</select>

</form>


</body>
</html>

mikedean
07-26-2002, 11:45 PM
Before I forget bob, your URL shows up a "cannot display" error.
Right, back to case in hand. Thanks bob, and others, for the obvious time and effort in helping me - as you can see this isnt my forte, but if you need any help in Flash lemme know :o
The HTML you provided did the trick, but not as I really wanted - what I was after was removing the Go button from the TWIN drop down fields, and the page you supplied wont integrate with a twin box. I also fancied the primary field spotting that for some options the secondary field had only one option and going straight to the URL obviating the need for a second click.
Whatever, that was only an aesthetic consideration, and bearing in mind the help youve already provided I wont ask more and will simply use it 'as is' out of the box! Thanks again for your help(s), and BTW i agree with you re: the first option being a dummy irrespective of whether theres a Go button or not, it just looks better that way :thumbsup:
regards
Mike



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum