JQuery: changing an event from an html HTML control cancels a Click event from an html button (direct events)

Can anyone help?

I have a change event in a text box and a click event on a button - all html.

Now, if I press a button, a click event will occur - great!

But I change something in the text box, and then I click the button, the event from the Change event happens, but it’s not, but I never get the button click event.

This is my jquery, is there any way around this. I'm lost.

$('#myTextbox').live('change', function() { $.ajax({ type: "POST", url: "test.aspx/GetDate", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { alert('the date is ' + msg.d); } }); }); $('#myButton').live('click', function() { alert('i am in click'); }); 

EDIT

I created a very simple html form and, of course, the click event does not fire if the change occurs first. In fact, in this example, I used the blur event ... but its

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="Scripts/jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function() { $('#htmlbutton').bind('click', function() { alert('i am in click'); }); $('#htmltextbox').bind('blur', function() { alert('in blur'); }); }); </script> </head> <body> <form id="form1"> <div> <input id="htmlbutton" type="button" value="button" /><input id="htmltextbox" type="text" /></div> </form> </body> </html> 
+4
source share
1 answer

It seems your warning is compressing the button click event. If instead of warning you change the color of both elements, you will see that both events are activated.

It happens that the blur / change event is triggered as soon as the mouse button is lowered onto the button. Since there is a warning, you have to go and click it, and it never registers the button on the button, which is what you need for the click event to shoot.

Ajax should complete and move on to the next event. If the call hadn’t returned so quickly that he still crushed the click.

+3
source

All Articles