Jump to content

Help With Naviagtion Function


dzhax

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...