Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Trevor Loader 199 posts 256 karma points
    Jul 20, 2011 @ 06:43
    Trevor Loader
    0

    How to delay a Base jquery submit

    I've got my /umbraco/base posting working well...in fact too well!  I want to delay the submit so the "pollsubmitting" message stays on the screen for 2 seconds.

        $(function({
          $(".submit").click(function(e){       
            jQuery("#poll").hide();
            jQuery("#pollsubmitting").show();
            jQuery("#poll .submit").attr("enabled"false);
            var url "/base/Poll/SubmitAnswer/" e.target.value ".aspx";   
            var pollIdvar jQuery(".poll #pollId").val();   
            -- PUT DELAY HERE --        
            jQuery.post(urlpollIdpollIdvar },
              function(data){
                 var null;
              }
            );
          });
        });

     

    I've looked at .delay() and setTimeOut but can't get either to work.

    Any Jquery gurus out there wanting some karma? 

  • Lee Kelleher 4025 posts 15835 karma points MVP 13x admin c-trib
    Jul 20, 2011 @ 07:11
    Lee Kelleher
    0

    Hi Trevor,

    I'd go with a setTimeout...

    $(function(){
        $(".submit").click(function(e){
            jQuery("#poll").hide();
            jQuery("#pollsubmitting").show();
            jQuery("#poll .submit").attr("enabled", false);
            var url = "/base/Poll/SubmitAnswer/" + e.target.value + ".aspx";
            var pollIdvar = jQuery(".poll #pollId").val();
     setTimeout( function() { jQuery.post(url, { pollId: pollIdvar }, function(data){ var a = null; }); }, 2000 );
        });
    });

    I haven't tested this, (obviously its set-up for your AJAX call), but I "think" that the values for "url" and "pollIdvar" should be stored within the closure - otherwise they may need to be declared as global variables. (I can already feel the evil looks from JS purists for suggesting that!)

    Cheers, Lee.

  • Trevor Loader 199 posts 256 karma points
    Jul 20, 2011 @ 07:22
    Trevor Loader
    0

    Hmmm...your setTimeout syntax is exactly what I've tried before and it didn't work.  I've used yours and also tried with global vars but all has the same result.  Quick post and full page refresh.

    Do I need to somehow stop the "default" submit?

    Any other ideas?

    T

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Jul 20, 2011 @ 07:35
    Aaron Powell
    1

    You need to stop the event - http://api.jquery.com/event.preventDefault/

  • Trevor Loader 199 posts 256 karma points
    Jul 20, 2011 @ 07:57
    Trevor Loader
    0

    Ahaaa - that was the little gem that I was missing.  Thanks slace (and lee).

Please Sign in or register to post replies

Write your reply to:

Draft