PHP/Javascript: Restart Form Button Isn't Working, Code Insde

Posted by Josh K on Stack Overflow See other posts from Stack Overflow or by Josh K
Published on 2010-05-13T18:36:17Z Indexed on 2010/05/13 18:44 UTC
Read the original article Hit count: 181

Filed under:
|

Basically I want a confirmation box to pop up when they click the button asking if they sure they want to restart, if yes, then it destroys session and takes them to the first page. Heres what i got...

echo "<form id=\"form\" name=\"form\" method=\"post\" action=\"nextpage.php\">\n";
echo "  <input type=\"button\" name='restart' value='Restart' id='restart'
        onclick='restartForm()' />";

and for the script...

<script type=\"text/javascript\">
     <!--
    function restartForm() {
    var answer = confirm('Are you sure you want to start over?');
    if (answer) {
        form.action=\"firstpage.php\";
        session_destroy();
        form.submit();
    } else
        alert ('Restart Cancelled');
    }
    // --
</script>";

EDIT: Note that pressing the button brings up the confirm box, but if you click okay nothing happens sometimes. Sometimes if u click cancel it still submits the form (To the original action)

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript