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.
Possible?
Moderator: General Moderators
-
nowaydown1
- Forum Contributor
- Posts: 169
- Joined: Sun Apr 27, 2008 1:22 am
Re: Possible?
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:
Then in your mypage.php file:
Hope that helps.
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>
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;
}
?>
-
benjaminj88
- Forum Newbie
- Posts: 21
- Joined: Fri May 02, 2008 2:31 pm
Re: Possible?
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
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Possible?
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?
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?
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>