You are hereFirefox canceling problem solved

Firefox canceling problem solved


By Gerd Riesselmann - Posted on 17 April 2005

I'd like to thank Johannes Hölzl, who pointed out my stupid mistake regarding canceling form submission in Firefox:

The
ECMAScript binding for DOM Events
says that the EventListener (which is the function "cancel") hasn't any returnvalue. But you get as parameter an Event object, where you can call "stopPropagation()" or "preventDefault()".

So I replaced this code:

function cancel()
{
  return false;
}

with this:

function cancel(e)
{
  if (e && e.preventDefault)
    e.preventDefault(); // DOM style
  return false; // IE style
}

and it works. I updated the test page accordingly.

Thanks a lot, Johannes!

just saved my behind too. thanks!

Me too, thanks!

Ahh my rear part is saved too. Thankyou very much.

You're a star. Saved me hours of frustration. Thanks

Thanks a million Gerd. I'd been trying all sorts, cancelBubble, etc, but tried this and it worked first time!

Cheers

Mickey

Really appreciate u. My problem is solved.

how's that work ?
what is e ?
when can i call that function ?

please email me.

Thanks

Hi, thanks for tips. Just what I needed to get it to work in firefox.

Btw, I stumbled upon this page:
http://talideon.com/weblog/2005/03/js-memory-leaks.cfm

It's a event manager that minimizes memory leaks involved in using closures with javascript.

Thank you soooo much!

Fantastic!

Thanks from me too, been driving me mad

Hello,
I have been unable to get the following code segment to cancel a page submit on a click action for a navigation link on a .jsp file. I am curious if the success of this code is dependent on the type of web page that implements it. i.e, is there a difference between standard HTML vs JSP?
When I click the Command Link the preventDefault code is executed as expected but does not prevent the page from navigating to next page.
Any insight you can provide would be very much appreciated.


function callValidation(obj, e){
Call to another function in a .js file that tests page input...
If that call returns false then run the following code...{
if (e && e.preventDefault){
e.preventDefault(); // DOM style
return false; // IE style
}
}
else{return true;}
}

Here is the code segment in the .jsp file that calls the function above...

Thankyouthankyouthankyou. After hours of trial and error, I was really losing the will to live. I even contemplated adding an onclick="return false;" to my code - particularly ironic when you consider that I attach every event via onload in order to make it unobtrusive.
I have to say that IE's handling seems to be far more obvious - at least it doesn't fly in the face of 10 years worth of Javascript best practice.

f.

Thank you for this helpful tip. It worked fine. It saved lot of our time. Thank you again for this posting

Thanks for saving me some headaches while writing my generic form validator.

Solution example for the mootools users amongst us:


$$('FORM')[0].addEvent('submit', function(e)
{
new Event(e).stop(); // stopt event propagation for firefox.
return this.validateAll();
}.bind(this));