Jump to content

Onclick Will Work For Alert, But Not Functions.


MrFish
 Share

Recommended Posts

I made a login but when you try and click the Logout text nothing happens. The onClick sends it to the ajaxLogout() function but when I change it to a simple alert() it works fine.

<?echo '<a>' . $_SESSION["username"] . '</a> | Messages(<a>#</a>) | Online Friends(<a>#</a>) | <a onClick="ajaxLogout()">Logout</a>';?>

Full Code

...<!-- AJAX LOGOUT -->	function ajaxLogout(){		alert('dun dun duuuun!');	}</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html> <head> <title> Index</title> <link rel="stylesheet" type="text/css" href="default.css"> </head> <body> <div id="ghost"> 	<div id="userbar"> 		<div id="userbarsubwrapper"> 			<a>mrfish</a> | Messages(<a>#</a>) | Online Friends(<a>#</a>) | <a onClick="ajaxLogout()">Logout</a>		</div> 	</div> 	<div id="wrapper"> 		<div id="subwrapper"> ...

I took out any ajax scripts and put in a simple alert to test and make sure it wasn't the logout script that had errors.

Edited by MrFish
Link to comment
Share on other sites

You have your script tag before the doctype. Nothing goes before the doctype. Script tags go in either the head or the body. Other than that, if your logout function isn't working correctly then check for Javascript errors. If you're not sure what's happening post the code for the function.

Link to comment
Share on other sites

Also, I think in the instance of framing the text as an anchor, the standard way to call a function is to use the javascript pseudolink:<a href="java script:functionName()"> </a>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...