PHP/Javascript: Restart Form Button Isn't Working, Code Insde
- by Josh K
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)