Help - Search - Members - Calendar
Full Version: Drop Down Menu
HTMLHelp Forums > Programming > Client-side Scripting
RickStick
How do I cause an option in a drop down menu to do nothing at all? In other words, when the user selects that link and clicks go, I want nothing to happen at all. Thanks for the help, much appreciated.
RickStick
here's the code for clarification:

CODE

<select name="Comprehensive List"ONCHANGE="window.open(this.options[this.selectedIndex].value)">
<option value=""selected>&lt;select&gt;</option>
<option value="www.whatever.com">Option1</option>
<option value="www.whatever.com">Option2</option>
</select>


The second line of code is the one I can't figure out how to deal with. Notice that I use the 'onchange' command. As it stands, "select" pre-populates the space as the first drop down menu option. I do not want a blank window to open if the user re-selects "select" (which is what happens now). Rather, I want "select" to do nothing if the user re-selects it.

Thank you.
Frederiek
You'll probably find an answer at http://www.cs.tut.fi/~jkorpela/forms/navmenu.html.
Christian J
Keep in mind that such a menu can be annoying for the user, e.g. if they slip with the mouse. Also search engines (and some human users) may have trouble following javascript-dependent menus, even though Google is said to recognize full URLs in scripts nowadays. See also the link Frederiek posted.

------

Regarding the example script, you'll need to make an exception for the empty one with say

CODE
if(this.options[this.selectedIndex].value!='') {window.open(this.options[this.selectedIndex].value);}


You should also insert an "http://" before the "www" part of the non-empty OPTION values.

You may also want to add a space between attributes, can't remember if it's valid HTML not to do it but at least it looks neater. happy.gif
pandy
QUOTE
The second line of code is the one I can't figure out how to deal with. Notice that I use the 'onchange' command. As it stands, "select" pre-populates the space as the first drop down menu option. I do not want a blank window to open if the user re-selects "select" (which is what happens now). Rather, I want "select" to do nothing if the user re-selects it


I think you need to change the script. The HTML attribute 'disabled' doesn't stop JS IIRC. Maybe you could let the script check that the value isn't empty before it goes on?
Christian J
QUOTE(pandy @ Jul 6 2009, 03:40 PM) *

The HTML attribute 'disabled' doesn't stop JS IIRC.

Where is DISABLED used?

QUOTE
Maybe you could let the script check that the value isn't empty before it goes on?

*cough*

pandy
QUOTE
Where is DISABLED used?


In the OPTION tag, but I'm saying it wouldn't help.

QUOTE
QUOTE
Maybe you could let the script check that the value isn't empty before it goes on?

*cough*



OK, so I didn't read all of it. rolleyes.gif
Christian J
QUOTE(pandy @ Jul 6 2009, 05:38 PM) *

QUOTE
Where is DISABLED used?


In the OPTION tag, but I'm saying it wouldn't help.

No it's a SELECTED attribute.
pandy
I'm not saying the OP is using it. I'm saying it wouldn't help. (Actually, it would, but not in all browsers.)
Christian J
Aha, now I understand! smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.