views:

690

answers:

2

Hi,

I am having an issue with a jquery function. It works in FF but not in IE 6. I want the function to be triggered when any option inside a select drop down is clicked. Here is the start of my funcation:

$('#titleSelect option').click( function() {    
    alert("title clicked");
    ......
});

Here is my drop down list:

<select id="titleSelect">
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

So in FF, the alert is triggered but in IE it is not. Is there any sort of an issue with IE recognizing the click event on a select and if so is there any way around it.

+3  A: 

why you don't use the onChange event? like:

$('#titleSelect').change( function() {    
alert("title "+$(this).val()+" clicked");
......
});

the jQuery change-event documentation you can find here:

http://docs.jquery.com/Events/change#fn

snuffer.ch
Thanks for that. Works perfectly, I suppose I was using .click for everything else and never even thought to look for another event that might work. Damn differences between IE and FF!
Caroline
+1  A: 

If you look at this page, go to the bottom, the Applies To section, and you can see that the option element is not in the list.

http://msdn.microsoft.com/en-us/library/ms536913%28VS.85%29.aspx

If you really want an event on the option element then look at the events on this page (click on the word events in the table): http://msdn.microsoft.com/en-us/library/ms535877%28VS.85%29.aspx#

Otherwise, just react to the onchange event on the select element and you will know when something is changed, but, that means that if they click on the event that was already selected then no event will fire.

James Black
Thanks James. I think both answers here were referring to using the change instead of click event. Fixed now, thanks again.
Caroline