如何设置自动提交定时器


how to set auto submit with timer

请帮助我解决我无法将自动提交到quizes的问题。在我提交后,计时器将刷新。

<?php
    //get the value of all the needed information
    $student_sql = mysql_query("SELECT * FROM students WHERE student_id='$_SESSION[student]'  LIMIT 1");
    while($s = mysql_fetch_array($student_sql)) {
        $fname = $s["first_name"];
        $lname = $s["last_name"];
        $_SESSION['first_name'] = $fname;
    }
    $question_sql = mysql_query("SELECT * FROM questionnaire WHERE questionnaire_id='$_SESSION[questionnaire]'");
    while($q = mysql_fetch_array($question_sql)) {
        $total = $q["questionnaire_total"];
    }
    $cat_sql = mysql_query("SELECT * FROM question WHERE category_id='$_SESSION[question]'");
    while($y = mysql_fetch_array($cat_sql)) {
    $cate = $y["category_id"];
        }
    define("NL","<br>'n");
    $status = "true";
    if(!isset($_POST["set"])) {
        $_SESSION["i"] = 0;
        $_SESSION["correct"] = 0;
        $_SESSION["incorrect"] = 0;     
    }
    if(isset($_POST["set"])) {
        if($_POST["submit"]) {
            if($_SESSION["i"] == $total) {
                unset($_SESSION["i"]);
                #unset($_SESSION["correct"]);
                #unset($_SESSION["incorrect"]);
                #$_SESSION["correct"] = 0;
                #$_SESSION["incorrect"] = 0;
                $_SESSION["i"] = 0;
                header("location: evaluate.php");
            }
            if(empty($_POST["choice"])) {
                $_SESSION["incorrect"] = $_SESSION["incorrect"] + 1;
                $status = "false";
            }
            if(!empty($_POST["choice"])) {
                if($_POST["choice"] == $_POST["answerswer"]) {
                    $_SESSION["correct"] = $_SESSION["correct"] + 1;
                }
                if($_POST["choice"] != $_POST["answerswer"]) {
                    $_SESSION["incorrect"] = $_SESSION["incorrect"] + 1;
                }
                $status = "true";
            }
            if($status == "true")
            $_SESSION['correct'];
        }
    }

        <div class="row">
                <div class="col-lg-5">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                         <h4><font color="#00CC00">Login As: <?php echo $fname." ".$lname.".";?>
                </font></h4>
                </div>
                            </font> 
                        </div>


        <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                      <input name="set" type="hidden" value="set">
                      <?php
                     $cat = $_SESSION["question"];
                            $sql = "select * from question WHERE category_id='$cat' ORDER BY RAND() LIMIT 1";
                            $result = mysql_query($sql);
                            $row = mysql_fetch_array($result);
                                echo $_SESSION[i]+1 .".) ".$row[question].NL;
                                $show_choice = mysql_query("SELECT * FROM choices WHERE question_id='$row[question_id]'");
                                while($show = mysql_fetch_array($show_choice)) {
                                    echo "<input name='"choice[$_SESSION[i]]'" type='"radio'" value='"$show[choice_1]; ?>'">".$show["choice_1"].NL;
                                    echo "<input name='"choice[$_SESSION[i]]'" type='"radio'" value='"$show[choice_2]; ?>'">".$show["choice_2"].NL;
                                    echo "<input name='"choice[$_SESSION[i]]'" type='"radio'" value='"$show[choice_3]; ?>'">".$show["choice_3"].NL;
                                    echo "<input name='"choice[$_SESSION[i]]'" type='"radio'" value='"$show[choice_4]; ?>'">".$show["choice_4"].NL;
                                    echo "<input name='"answerswer[$_SESSION[i]]'" type='"hidden'" value='"$show[answer]; ?>'">".NL;
                                    $_SESSION["i"] = $_SESSION["i"] + 1;
                                }

                      ?>
                      <input name="submit" type="submit" class="btn btn-success" value="Continue">
                    </form>

使用javascript实现它:

window.setTimeout(function(event) {
    $('form').submit();
}, 1000);
$('form').on('submit', function(event){ 
    event.preventDefault();
    alert('submited')  
})

此处的示例:http://jsfiddle.net/DariuszMusielak/3pkmb49x/1/