Hi,
I'm a newbie to DOM scripting and have run into a problem that was not able to solve with all my books and online sourcces :-(
So I hope someone could explain how to remove the standard event from a submit button, I mean how can I prevent the submit button from actually submitting something?
Here's what I've tried so far (simplified):
First I attach a new event to the submit button (using the "addEvent" - cross-browser workaround from Scott Andrew):
function submitHandler () {
submitBtn = document.getElementsByName(submitButtonName)[0];
addEvent(submitBtn,"click",alertbox,false);
Then I handle the click on the submit button with my function
function alertbox () {
alert("This is not allowed");
return false;
}
The code works just fine until the alert box pops up. But then after clicking "OK" in the alert box the form will still be submitted (what it should not) - but only in Firefox. IE7 does not submit the form and halts after the alert box, just how it's supposed to be.
I've been playing around with stopPropagation, preventDefault and a lot of functions that I found online, but I just can't get it to work - I just got the feeling that this is some kind of secret science. And I'm afraid I don't even know where do I have to put event removing part - I guess somewhere in the alertbox() function... ???
Can anyone enligten me on this, any tiny hint would be much appreciated!
Thanks a lot,
sdevic



Reply With Quote

Bookmarks