I have a button which is enabled/disabled via validation. Users were reporting that sometimes the button takes two clicks to do activate.
After some debugging, I've narrowed this down to when the button is enabled in the same "focusout" event which clicks it.
Here is some sample code which shows the problem:
- <a id="my-button" href="#">My Button</a>
- <input type="text" id="fname" name="fname" />
- <span id="message"></span>
- <script type="text/javascript">
- $("#my-button").button();
- $('#my-button').click(function(event){
- alert("enabled and clicked");
- });
-
- $("#fname").focusout(function() {
- $('#my-button').button('enable');
- document.getElementById("message").innerHTML += '-focusout-';
- });
- </script>
If the focus is in the text box when the user clicks the button then the click event is 'lost'.