dzhax Posted April 24, 2009 Share Posted April 24, 2009 I am trying to use a function to navigate to certain pages acording to the $location variable sent to it from an onclick function. <img onclick="autoNav(index)" src="files/navbutton.php?text=Home&left=35"><?phpfunction autoNav($location){ header('Location: index.php?action='.$location);}?> Anyone see anything wrong or know how to make this work? Link to comment Share on other sites More sharing options...
jeffman Posted April 24, 2009 Share Posted April 24, 2009 You're trying to use a DOM event on the browser to trigger a server command. It's not gonna happen (not without AJAX, anyway). PHP code all gets processed on the server before the browser receives the document. Your onclick event will go looking for a javascript function called autoNav(). But because autoNav() exists inside the PHP tags, it does not get downloaded to the browser, so it cannot be found. And browsers don't speak PHP.An equivalent javascript function might look like this: function autoNav(my_location) { location = 'index.php?action=' + my_location;} I won't swear to it, because I don't know what you're passing in index. Link to comment Share on other sites More sharing options...
dzhax Posted April 24, 2009 Author Share Posted April 24, 2009 Thanks man. Kinda figured it was something like that. Not sure tho. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.