![]() |
should I return false? and what happened to the click?
hello,
I'm working on a greasemonkey script that has a form (that isn't really a form, but just a collection of inputs - otherwise I guess I would be using beforesubmit) which is submitted somehow (dunno how, hoping not to have to find out) on the click of a button. What I want to do is do a validation on the "form" before it gets sent. I struggled for a while because I was adding a click listener to the button (making the validation happen after the info was sent), but I realised that using "mousedown" I get to sneak in, and do the validation. I then just programatically click the submit button and away it goes. Which is great. Works fine on my machine, anyway. But I have two doubts. A validation error brings up a confirm. If you click OK, the form sends. If you click cancel it doesn't. But shouldn't there be a return false in there somewhere, even though you would be returning false from the mousedown which I guess is unrelated to the click? And that's the second question: The way I understand it, the event order is mousedown, click, mouseup. So what happens to the click event? Does it die while the confirm box is showing? Here's a very basic example which demonstrates this. It's in jQuery because the page uses jQuery and I have to attach listeners to the dynamically created button (which I have no control over) - I know I can do that in vanilla, but it's just easier this way. But anyway, this isn't a jQuery question - the jQuery works fine. What I'm asking is how the javascript works here. More than anything, why don't I need to be canceling the click event in some way? Any thoughts much appreciated. Code:
<html> |
Code:
if (confirm("You didn't check the box! Sure you want to continue?")) {Code:
if (confirm("You didn't check the box! Sure you want to continue?") == true) { |
Quote:
i don't think you can actually terminate/prevent a click() from a mousedown... the reason confirm/alert help is that it prevents the mouseup on the element with the click() event, thus ensuring that the button is not actually clicked. also , this test app shows this output: Code:
EVT: mousedownyou may want to stop pulling your hair; i found this text on the jQuery site: Quote:
|
Quote:
So, nobody use mousedown, please :D There was no hair-pulling going on. That it works is good enough for me. That it should work on non-windows OSs is even better. Thanks again for the info :thumbsup: |
| All times are GMT +1. The time now is 03:34 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.