Results 1 to 3 of 3

Thread: auto submit form on page refresh

  1. #1
    Join Date
    Aug 2013
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default auto submit form on page refresh

    Hi everyone, i need to auto submit a form on page refresh every 5 seconds.
    This is what i have done but does not work

    Code:
    <html>
        <head>
            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        </head>
        <body>
            <form id="myform" name="myform" action="POSTadat.php" method="POST">
                <input type="text" name="myname">
                <input type="submit">
            </form>
    
            <script>
                $(document).ready(function() {
                   setTimeout(function() {
                       $('#myform').submit();
                   }, 1000);
                   $('#myform').submit(function(e) {
                      e.preventDefault();
                   
                   }); 
                });
            </script>
        </body>
    </html>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This prevents the form from submitting:

    Code:
     $('#myform').submit(function(e) {
                      e.preventDefault();
                   
                   });
    It's kind of unclear what you really want to have happen. I think what you want is for the form to submit to the server without the page changing, and that you want this to happen every 5 seconds. If so, the form could be submitted via ajax as part of a setInterval loop of 5 seconds.

    But your post is so unclear to me that I hesitate to write out any code for it. Please state precisely what you want to have happen, and just as importantly why, so that I might understand what sort of help to give.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2013
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This is what am trying to achieve. Am retrieving values from database into a form inputs
    <input type=text name=message value="<?php echo htmlentities($message); ?>">
    I want the form to be auto submitting every 5 seconds whenever there is a value in the input form as fetched from database.
    If there is no value in the form input and 5 second has reached, let it not auto submit.

    Thank You

Similar Threads

  1. JavaScript Auto Submit Form
    By sysout in forum JavaScript
    Replies: 3
    Last Post: 01-24-2013, 02:38 PM
  2. Code to auto refresh page every day?
    By mlegg in forum HTML
    Replies: 4
    Last Post: 11-29-2011, 03:43 AM
  3. [Javascript] Auto Submit Form
    By sysout in forum JavaScript
    Replies: 5
    Last Post: 09-25-2009, 12:32 AM
  4. Form action Mailto need to open new page on submit and submit email
    By lstammer in forum Looking for such a script or service
    Replies: 0
    Last Post: 12-06-2007, 05:41 PM
  5. Auto Page Refresh
    By NGJ in forum JavaScript
    Replies: 8
    Last Post: 05-16-2006, 01:34 PM

Bookmarks

Posting Permissions

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