SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Drop-Down Menu Quirks
-
Dec 27, 2001, 23:37 #1
- Join Date
- Jun 2001
- Location
- Oklahoma
- Posts
- 3,392
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Drop-Down Menu Quirks
I'm using the following coding in the respective portions of a site.
Head:Code:<script language="javascript" type="text/javascript"> <!-- function formhandler(form) { var URL=document.websites.sites.options[document.websites.sites.selectedIndex].value; window.location.href=URL; } //--> </script>
Code:<form name="websites" action=""> <select name="sites" size="1" onchange="javascript:formhandler()"> <option selected="selected">Sites:</option> <option value="#">-------------------</option> <option value="http://www.somesite.com/">Somesite</option> </select> </form>
I put the hash mark (#) in there to alleviate this problem, however it did not do the trick.
Any ideas as to how to keep the script functioning when the dashes are selected?Colin Anderson
Ambition is a poor excuse for those without
sense enough to be lazy.
-
Dec 28, 2001, 00:25 #2
- Join Date
- Oct 2000
- Location
- Austin, TX
- Posts
- 1,438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Re: Drop-Down Menu Quirks
Try this:
Code:<form> <select size="1" onchange="formHandler(this)"> <option selected="selected">Sites:</option> <option>-------------------</option> <option value="http://www.somesite.com/">Somesite</option> </select> </form> <script type="text/javascript"> <!-- function formHandler(selectObj) { var url = selectObj.options[selectObj.selectedIndex].value; if (url != '') location.href = url; } //--> </script>
ck :: bringing chris to the masses.
-
Dec 28, 2001, 03:45 #3
- Join Date
- Jun 2001
- Location
- Oklahoma
- Posts
- 3,392
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks much Anarchos. That works beautifully.
Colin Anderson
Ambition is a poor excuse for those without
sense enough to be lazy.
-
Dec 28, 2001, 12:03 #4
- Join Date
- Feb 2000
- Location
- where the World once stood
- Posts
- 700
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can also pass the value itself and cut the function to 1 line:
<select size="1" onchange="formHandler(this.options[this.selectedIndex].value)">
......
function formHandler(optVal)
{
if (optVal != '') location.href = optVal;
}
VinnyWhere the World Once Stood
the blades of grass
cut me still
Bookmarks