Disable/enable onclick event

M

MEM

hello,

I'd like to 'disable' an image link based on a value selected in a
drop down.

I currently have an image link that has the onclick event set to
execute a function.

For example:

<a href="#" onclick="afunction();return false;"><img
src="blah.gif"></a>

So, based on what the user selects in a drop down i want the onclick
event to NOT execute the function.

On the opposite end i want the onclick event to execute the function
if nothing is selected from the drop down.

thanks in advance
 
R

Rick Measham

hello,

I'd like to 'disable' an image link based on a value selected in a
drop down.

I currently have an image link that has the onclick event set to
execute a function.

For example:

<a href="#" onclick="afunction();return false;"><img
src="blah.gif"></a>

So, based on what the user selects in a drop down i want the onclick
event to NOT execute the function.

On the opposite end i want the onclick event to execute the function
if nothing is selected from the drop down.

thanks in advance

When you say 'nothing is selected from the drop down' I assume you mean
if the selectedIndex is 0. In which case:


<a href="#" onclick="if (theDropDown.selectedIndex > 0) {
afunction(); } else {document.location='http://www.google.com'}">



That will take you to google if nothing is selected in the drop down.

It will execute afunction() if something it selected in the drop down.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top