andrew_ww Posted May 22, 2007 Share Posted May 22, 2007 Hello, I'm trying to convert this: <a href="<?php echo $logout; ?>" class="style1">Log out</a> so that it works in the onclick event, I've tried this - but it does not work: <input type="BUTTON" class="style2" onClick="<?php echo $logout; ?>" value="Log Out"> the actual logout code is this: // Logout link $logout = $_SERVER['PHP_SELF']."?begone=true"; // If user chooses to logout unset session and redirect if(isset($_REQUEST['begone']) && $_REQUEST['begone'] == true) { $_SESSION['authenticated'] = NULL; unset($_SESSION['authenticated']); header("location: ../home.php?notification=loggedout"); } Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/52483-adding-php-code-to-javascript-onclick-event/ Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 a) javasript issue b) you'd need to use document.location.href (buttons have to be told to act like links ) Quote Link to comment https://forums.phpfreaks.com/topic/52483-adding-php-code-to-javascript-onclick-event/#findComment-258986 Share on other sites More sharing options...
jitesh Posted May 22, 2007 Share Posted May 22, 2007 <input type="BUTTON" class="style2" onClick="javascript:window.location.href='<?php echo $logout; ?>'" value="Log Out"> Quote Link to comment https://forums.phpfreaks.com/topic/52483-adding-php-code-to-javascript-onclick-event/#findComment-258988 Share on other sites More sharing options...
andrew_ww Posted May 22, 2007 Author Share Posted May 22, 2007 thanks very much the code - it worked a treat. Quote Link to comment https://forums.phpfreaks.com/topic/52483-adding-php-code-to-javascript-onclick-event/#findComment-259002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.