ashrobbins87 Posted March 12, 2009 Share Posted March 12, 2009 How do I make a button carry out the functionality from a separate php file? I wanting to make a logout button, and the script is... <?php setcookie("auth"); header("Location:home.php"); exit; ?> and the code I've tried to use to make the button carry out the functionality is... <input type="button" name="Logout" value="Logout" onClick="cmslogout.php"> No joy. Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/ Share on other sites More sharing options...
jackpf Posted March 12, 2009 Share Posted March 12, 2009 You can't just put a url in javascript, you have to do something like this- onclick="window.location='logout.php'" Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783135 Share on other sites More sharing options...
RichardRotterdam Posted March 12, 2009 Share Posted March 12, 2009 actually you just make a link to a script that logs you off <a href="logout.php">logout</a> ofcource you'll need to write the logout script Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783208 Share on other sites More sharing options...
jackpf Posted March 12, 2009 Share Posted March 12, 2009 actually you just make a link to a script that logs you off well actually not if he wants a button, which he stated in his original script... Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783279 Share on other sites More sharing options...
RichardRotterdam Posted March 13, 2009 Share Posted March 13, 2009 actually you just make a link to a script that logs you off well actually not if he wants a button, which he stated in his original script... true. But in the big picture what should matter more is what it does and not what tag it uses. Using a link instead of a <input /> or <button /> tag makes it possible to log out without javascript. You wouldn't want someone to turn on javascript just so they can log out. Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783587 Share on other sites More sharing options...
Festy Posted March 13, 2009 Share Posted March 13, 2009 <a href="logout.php"><img src="button.jpg" border="0" /></a> OR <a href="javascript: window.location.href='logout.php' ;" ><img src="button.jpg" border="0" /></a> OR <input type="button" value="Log Out" onclick="window.location.href='logout.php'"/> Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783601 Share on other sites More sharing options...
ashrobbins87 Posted March 13, 2009 Author Share Posted March 13, 2009 Thank you everyone for all your help, at the moment the code I've got is... <a href="logoutcms.php"><input type="button" name="Logout" value="Logout"></a> ...but for some reason this wont work in IE. I have tested in Firefox and Chrome and its fine but is there any reason why IE wouldn't like it?? Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783619 Share on other sites More sharing options...
RichardRotterdam Posted March 13, 2009 Share Posted March 13, 2009 use an image instead and it should work fine <a href="logoutcms.php"><img src="logout.gif" alt="logout"/></a> Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783631 Share on other sites More sharing options...
dgoosens Posted March 13, 2009 Share Posted March 13, 2009 just use a simple form <form action=logoutcms.php method=GET> <input type=button name=logout value=logout /> </form> no JavaScript and this will work in all the browers Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783632 Share on other sites More sharing options...
grissom Posted March 13, 2009 Share Posted March 13, 2009 If you have an <INPUT TYPE = "BUTTON" etc... have you enclosed it within some <FORM></FORM> tags, if not, that might cause some browsers to not interpret it right. Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783635 Share on other sites More sharing options...
ashrobbins87 Posted March 13, 2009 Author Share Posted March 13, 2009 I've tried all of these solutions, and they dont seem to work in any browser, not just IE! ??? The <input...> tag is enclosed within <form> tags, I also tried using the ... <form action="logoutcms.php" method="GET"> ...that was suggested but no joy... Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783638 Share on other sites More sharing options...
dgoosens Posted March 13, 2009 Share Posted March 13, 2009 I've tried all of these solutions, and they dont seem to work in any browser, not just IE! ??? The <input...> tag is enclosed within <form> tags, I also tried using the ... <form action="logoutcms.php" method="GET"> ...that was suggested but no joy... try by using this <form action=logoutcms.php method=GET> <input type=submit name=logout value=logout /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783639 Share on other sites More sharing options...
ashrobbins87 Posted March 13, 2009 Author Share Posted March 13, 2009 yeah thanks a lot goosens!! just changed the input type from button to submit and now it all works. Thanks a lot to everybody who suggested a fix! Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-783643 Share on other sites More sharing options...
Daniel0 Posted March 15, 2009 Share Posted March 15, 2009 <form action=logoutcms.php method=GET> <input type=submit name=logout value=logout /> </form> Your markup is invalid. You're mixing HTML and XHTML syntax. You need to either enclose attribute values in single or double quotes, or you need to remove the self closing part of the input tag. Quote Link to comment https://forums.phpfreaks.com/topic/149140-solved-make-a-button-use-a-script/#findComment-785066 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.