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 3945 posts 15163 karma points MVP 10x 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 3044 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).

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies