SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
-
Aug 21, 2007, 08:31 #1
- Join Date
- Jun 2007
- Posts
- 25
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Firefox does not cancel form submit via dynamically added functions
I am using a custom form validation framework built on top of the Prototype framework.
Code JavaScript:Event.observe('loginForm', 'submit', function(){ return _fv.validate(_h); });
When I use this in my login.js file, it does not do the trick in Firefox. I have searched Internet for quite some time, but I couldn't find the elegant solution once I stumbled upon. Looks like I was not wise enough to save it.
Now there are methods like <form ... onsubmit="return blabla()">. But I want all my javascript code in separate files. This was also discussed in some elder forum/blog entries, with solutions not too stylish in my context.
Currently I am using this temporary solution:
Code JavaScript:function onLogin() { return _fv.validate(_h); } $('loginForm').onsubmit=onLogin;
-
Aug 21, 2007, 09:04 #2
- Join Date
- Jul 2007
- Posts
- 345
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Within your event listener you can prevent submission by cancelling the default action:
Code:function validator(e) { e = e || window.event; // validate // if fails validation e.returnValue = false; // IE way if (typeof e.preventDefault != undefined) { e.preventDefault(); // W3C way } }
Bookmarks