webmaniacgr
webmaniacgr

Reputation: 703

drop down menu: how to make deactivate the 1st (selected) option?

Here is the dropdown I'm using:

<form name="my_form_name">
<select name="my_ddmenu_name">
<option value="#" selected>dd menu title (should not act as a link)</option>
<option value="link to page 1">1st Link name</option>
<option value="link to page 2">2nd Link name</option>
<option value="link to page 3">3rd Link name</option>
<option value="link to page 4">4th Link name</option>
<input type="button" name="Submit" value="Go!" onClick="window.open(ddmenu1.value,'newtab')">
</select>
</form>

It's necessary for me to - have a "Go" link, as above. Users should select their link of choice and then press "Go!" to visit the selected link. - open links in a new tab, as above.

So, how should I change the code above to deactivate the 1st (selected) option's link (currently leading to "#").

Thank you.

Upvotes: 3

Views: 310

Answers (3)

karim79
karim79

Reputation: 342795

How about:

onClick="if(ddmenu1.value !== '#')window.open(ddmenu1.value,'newtab')"

Demo.

Upvotes: 2

Har
Har

Reputation: 5004

Your Go button must trigger a custom javascript that checks the value of your dropdown and then does the fancy link work. JQuery would be my preference.

Upvotes: 0

Julian D.
Julian D.

Reputation: 5463

Try

<option value="#" selected disabled>dd menu title (should not act as a link)</option>

Upvotes: 0

Related Questions