onsubmit in form in Safari (windows)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rudiedirkx
    New Member
    • Jan 2010
    • 7

    onsubmit in form in Safari (windows)

    Gents,

    I have a problem (only in Safari) with the onsubmit in webforms. This topic covers the same subject: http://bytes.com/topic/javascript/an...nsubmit-safari but not as detailed as I will.

    Let me illustrate the problem with examples.
    The HTML:
    Code:
    <html>
    
    <head>
    <script type="text/javascript" src="/js/mootools_1_11.js"></script>
    <script type="text/javascript">
    function postForm(f, c) {
    //	$(f).send({onComplete: c});
    	return false;
    }
    </script>
    </head>
    
    <body>
    
    <form method="post" action="other_page.html" onsubmit="return postForm(this,function(t){alert(t.length);});">
    	<input type="text" name="oele" value="boele" />
    	<input type="submit" value="Submit" />
    </form>
    
    </body>
    
    </html>
    As you can see, Mootools is my JS library (love it!). The onsubmit calls postForm with the form and a handler functions as arguments. postForm should than post the form with Ajax and call the handler ($(form).send() does that). The postForm functions returns false, and the onsubmit returns postForm, so that FALSE is in fact returned to the webform. With the $(f).send() commented (like now), it "works": the form isn't posted and the page doesn't change. But Ajax does nothing! With the (very important) line uncommented, the form posts! The page changes! << ONLY in Safari! The rest (firefox, chrome, internet explorer and opera) work fine.

    So I thought, maybe returning false just isn't enough SOMETIMES (because obviously sometimes it IS enough). So Mootools has a stop function for events (where the submit is the event). So I added this to the postForm function:
    Code:
    new Event(window.event).stop();
    making the function look like this:
    Code:
    function postForm(f, c) {
    	new Event(window.event).stop();
    	$(f).send({onComplete: c});
    	return false;
    }
    In a way that was a solution: the form didn't post anymore and the page didn't change. But the Ajax request didn't fire either!! So the event.stop() halted the entire event and it's child process(es)! Again: in Firefox, Chrome, IE and Opera, this method works fine.

    Does anyone know the problem and a solution? It doesn't have to be pretty, but it has to be possible with Mootools. Thanks a bunch
    Attached Files
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    I don't know if this might be the solution, but often when something like this happens, there's a JavaScript error which causes it, i.e. when there's an error in the script, the rest of the code will be ignored and the form will be posted. That means there may be a problem in the Mootools send method in Safari. Not definite by any means, but something you could look into.

    Comment

    • rudiedirkx
      New Member
      • Jan 2010
      • 7

      #3
      A litte late but very thankful.
      acoder, you were absolutely right. And the error was my own fault :( I edited the mootools lib so that Safari didn't understand it anymore, which led to a very indirect javascript Type error.
      And now it works! Perfect!

      Comment

      Working...