0

I have an HTML dropdown menu. I have a jquery .live() 'click' event listener attached to the select element.

In Chrome, it seems that the event fires after I click an option. So if I click it just once to drop the menu, the event has not yet fired. I must click one of the options to fire the event.

In Firefox, it seems that the event fires as I drop the menu. I do not need to click an option because the event has already fired.

This has been a bug in my code for 2 years. I have avoided fixing it by working in a very small shop, but I finally zoomed in close enough to see this up close. I am in conflict since I feel as though this is a discrepancy but I am seasoned enough to know the odds are that I don't understand something.

Edit: adding some code. I can't add the whole page.

<td class="action">
  <select id="action_x1" class="action_selector"> 
    <option value="one">one</option>
    <option value="two">two</option>
  </select><button id="action_x1">commit</button>
</td>

Then the javascript:

$(".action_selector").live({
  'click': function (){ show_action_edit_form( $(this) ); }
});

function show_action_edit_form( element ){
  console.log("oh, you clicked me.");
}
5
  • 2
    Can you post your code sample? Commented Jun 12, 2013 at 20:41
  • Since this has been around for 2 years now, I'm assuming you're also using an older version of jQuery, yes?
    – tymeJV
    Commented Jun 12, 2013 at 20:43
  • Upgrade to a newer version of jQuery. Use .on('change',[...]. That should fix it. The event should fire in all browsers after a value is selected. Commented Jun 12, 2013 at 20:45
  • I am on jquery 1.7.1. I have tried upgrading along the way. I will try a more current one. Edit: 1.8.1 yields the same. 1.9.1 and above break my code, so I will have to investigate patching it up to experiment with versions that new and newer.
    – mike
    Commented Jun 12, 2013 at 20:48
  • The issue with .on('change') is that I need to get in when the menu is dropped down. I use this event to flag an asynchronous updater to pause. The effect is that someone using the form who clicks the drop down will have the drop down reset if they have not clicked on an option by the time the updater fires again. In firefox, it works as I desire since the event fires on the initial drop down, pre-option-selecting.
    – mike
    Commented Jun 12, 2013 at 20:57

1 Answer 1

1

My wife ended up figuring this out.

The event I need to bind to is 'focus', not 'click'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.