Hi the logout button is not working in chrome. It is working fine in Firefox. However if I press F12 and keep the developer console open then the button works. The button also works when I press enter. I'm confused. Here is my code.
HTML Code:
<form name="logoutform" method="post" onsubmit="logoutConfirmation()" action="" >
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>
JS Code:
function logoutConfirmation()
{
alert("Thank you. Have a nice day!");
}
PHP Code:
if(isset($_POST['userlogout']))
{
setcookie('user_name', '');
setcookie('user_id', '');
session_destroy();
header("Location: index.php");
}
Define the action php file in your form like;
<form name="logoutform" method="post" onsubmit="logoutConfirmation()" action="yourfile.php" >
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>
If you don't set action. It's not submitted.
Try something like this if your file is named "test.php":
<?php
echo <<<STR
<html>
<head>
<script>
// your script
</script>
</head>
<body>
<form method="post" name="logoutForm" onsubmit="logoutConfirmation();" action="test.php">
<input type="submit" name="userlogout" value="Logout" id="logoutButton">
</form>
</body>
</html>
STR;
?>
If the PHP script is in the same file then you don't even need action=""
.
Just do this:
<form name="logoutform" method="post" onsubmit="logoutConfirmation()">
<input type="submit" value="Logout" id="logoutbutton" name="userlogout" ><br>
</form>