www.webdeveloper.com
Results 1 to 6 of 6

Thread: How can I delay the submission of a form?

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    6

    Unhappy How can I delay the submission of a form?

    I've a forum (PHPBB) that uses form and submit button:

    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}">
    
    ...
    
    <input type="submit" accesskey="s" tabindex="6" name="post" id="sendp" value="{L_SUBMIT}" class="button1 default-submit-action" />

    I want to delay submission of a form to execute the JS function. I do like this:

    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}" onsubmit="return PreSubmit()">
    
    
    function PreSubmit()
    {
      setTimeout('alert("Hello")', 5000)
      return false;
    }

    But the form is sent immediately because the javascript is executed immediately. Is there no way to delay the submission of a form??? Thanx

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}">
    
    ...
    
    <input type="button" accesskey="s" tabindex="6" name="post" id="sendp" value="{L_SUBMIT}" class="button1 default-submit-action" onclick="setTimeout('PreSubmit(this.form)',5000)" />
    
    
    function PreSubmit(form){
    alert("Hello");
    form.submit();
    }

  3. #3
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by Padonak View Post
    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}">
    
    ...
    
    <input type="button" accesskey="s" tabindex="6" name="post" id="sendp" value="{L_SUBMIT}" class="button1 default-submit-action" onclick="setTimeout('PreSubmit(this.form)',5000)" />
    
    
    function PreSubmit(form){
    alert("Hello");
    form.submit();
    }


    Not working... The form is not sent after the alert
    Last edited by justman; 05-13-2012 at 07:41 AM.

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    ok let's try doing it this way

    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}">
    <input type="button" accesskey="s" tabindex="6" name="post" id="sendp" value="{L_SUBMIT}" class="button1 default-submit-action" onclick="PreSubmit(this.form)" />
    </form>
    
    function PreSubmit(form){
    var func=function(){alert("Hello");form.submit();}
    setTimeout(func,5000);
    }

  5. #5
    Join Date
    May 2012
    Posts
    6
    Quote Originally Posted by Padonak View Post
    ok let's try doing it this way

    Code:
    <form id="sendform" name="postform" method="post" action="{S_POST_ACTION}">
    <input type="button" accesskey="s" tabindex="6" name="post" id="sendp" value="{L_SUBMIT}" class="button1 default-submit-action" onclick="PreSubmit(this.form)" />
    </form>
    
    function PreSubmit(form){
    var func=function(){alert("Hello");form.submit();}
    setTimeout(func,5000);
    }
    Reset form fields...but the form is not sent. Maybe it is protected by PHPBB (forum). Please take a look this code:

    Code:
    <input type="hidden" name="creation_time" value="1336915640" />
    <input type="hidden" name="form_token" value="22b09178c8706196a990c6fe0cea8bbc258fa6dd" />
    
    		<fieldset class="submit-buttons">
    			
    			<input type="hidden" name="lastclick" value="1336915639" />
    			<input type="submit" accesskey="k" tabindex="7" name="save" value="Draft" class="button2" />&nbsp; 
    			<input type="submit" tabindex="5" name="preview" value="Preview" class="button1" onclick="document.getElementById('postform').action += '#preview';" />&nbsp;
    			<input type="button" accesskey="s" tabindex="6" name="post" id="sendp" value="Submit" onclick="PreSubmit(this.form)" class="button1 default-submit-action" />&nbsp;
    
    		</fieldset>
    Suspiciously...

  6. #6
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    the code i posted works because i tested it locally. i don't know why it doesn't work with phpbb - maybe some values are not sent

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles