Page 1 of 1

Possible?

Posted: Wed May 07, 2008 11:37 pm
by benjaminj88
Is it possible to get information from a html link? and use it in a php code?
What I am trying to figure out is a script which depending on the link will output a different code. For instance you have link1, link2, and link3 now when you hover over each link it will have a different code that will be passed along with it.

link name output
link 1 hi
link 2 hello
link 3 bye

more or less how can I pass a variable through a link to turn that variable to make an if statement with a hoverover.

Re: Possible?

Posted: Thu May 08, 2008 12:02 am
by nowaydown1
I'm not sure I follow what you're trying to accomplish. If you wanted to figure out what link was clicked on a remote PHP page you could do something like this:

So your hyperlinks would look like:

Code: Select all

 
<a href="mypage.php?action=update">update</a>
<a href="mypage.php?action=remove">remove</a>
<a href="mypage.php?action=hide">hide</a>
 
Then in your mypage.php file:

Code: Select all

 
<?php
 
$requestedAction = $_GET['action'];
switch($requestedAction) {
  case 'update':
    echo 'You ran update.';
    break;
  case 'remove':
    echo 'You ran remove.';
    break;
  case 'hide':
    echo 'You ran hide.';
    break;
  default:
    echo 'That action is not valid.';
    break;
}
 
?>
 
Hope that helps.

Re: Possible?

Posted: Thu May 08, 2008 5:06 am
by benjaminj88
honest it doesn't see what I am trying to do is have the variable effect the current page if at all possible, the links have a mouseover which will trigger and set the variable which will output something different with each link. Keeping one file open and not loading a new document, but where if the link is clicked it will take you to a different document, but thanks for the try

Re: Possible?

Posted: Thu May 08, 2008 5:16 am
by aceconcepts
It looks like nowaydown1 has got the concept correct.

Maybe you need to rephrase your question - seems a bit convoluted!

Also, try providing more info i.e. will the links be produced dynamically?

Re: Possible?

Posted: Thu May 08, 2008 1:02 pm
by califdon
If I understand what you are asking, you need to do this in Javascript, which is client-side language. So if you want something to happen to the current page, without loading a new script and new page, it has to be done in script that is already in the page that the browser can execute--client-side--Javascript. So something like this may be what you're looking for:

Code: Select all

...
<head>
<script type="text/javascript">
   function doit( txt ) {
      document.getElementById("msg").innerHtml = txt
   }
</script>
</head>
<body>
...
<a href="url1.html" onMouseOver="doit('hi');">Link1</a><br />
<a href="url2.html" onMouseOver="doit('hello');">Link2</a><br />
<a href="url3.html" onMouseOver="doit('bye');">Link3</a><br />
<div id="msg"> </div>