How to trigger an event ONLY if both dropdowns are selected?

Posted by DaveDev on Stack Overflow See other posts from Stack Overflow or by DaveDev
Published on 2010-06-01T15:22:45Z Indexed on 2010/06/01 15:33 UTC
Read the original article Hit count: 141

I have a dropdown select list on my page of class="TypeFilter".

I have a jQuery event that fires when a value in that list is selected.

$(".TypeFilter").change(function() 
{
    // Extract value from TypeFilter and update page accordingly
));

I now have to add another list to the page, and I want to implement functionality which will prevent the .change(function() from running unless both are selected.

In both lists the first option in the list is some text instructing the user to select one of the items, so I was thinking of just writing some logic to test that both lists have a selected index greater than 0.

I think this is a touch unclean though, especially considering that other pages that have a TypeFilter use the same logic.

Is there any nifty functionality in jQuery that can do this?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery