PHP onmouseover get image name.. ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
copyright
Forum Newbie
Posts: 2
Joined: Tue Jun 28, 2005 7:20 pm

PHP onmouseover get image name.. ?

Post by copyright »

Is there a way possible to put an image name in a variable when you put your mouse over it ? or anything else.. such as text..

like: [IMAGE] <-- when you put your mouse over it.. the code will..

$image = imagename.gif;

because [IMAGE] is a random image everytime.. any help would be appreciated.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
So you have [IMAGE] inside your webpage/HTML, what should happen when moving the mouse over it, open a new page, open a popup, just show an image?

This seems more like a JavaScript question. Use JS to redirect to a PHP-script and do whatever you want...

djot
-
copyright
Forum Newbie
Posts: 2
Joined: Tue Jun 28, 2005 7:20 pm

Post by copyright »

What should happen is:
onmouseover: get (image name), set ($image = "image name";)

(the image is always somewhat random so i never know what its gonna be)
basically all i need is something like:
<?
onmouseover:getsource(eg; whatever.gif);
$image = "thatsource";
?>
or
<?
$image = onmouseover:getsource
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

onMouseOver is a javascript event. You can't use it with php cause php isn't gonna know when you've moused over an object (it's server side).

you'd have to use JS to do what you're trying to do.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

The people in the Client-Side forum should know how to handle this one.

You're going to have to set up a javascript function that is triggered by the onMouseOver.

Something like <a href="#" onMouseOver="function();">

PHP is server side, and JavaScript is client side, so there's no way for the two to interact with each other.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

This should work:

Code: Select all

function send_image_name(passed_object)
{
  document.getElementById('variable_to_store_in') = passed_object.src;
}

Code: Select all

&lt;body&gt;
&lt;form&gt;
&lt;input type = 'hidden' id = 'variable_to_store_in'&gt;
&lt;img src = &quote;random.gif&quote; onMouseOver = &quote;send_image_name(this);&quote;&gt;
&lt;input type = 'submit'&gt;
&lt;/form&gt;
&lt;/body&gt;

This will store the src of the image in the hidden variable. You can then submit this form, sending the image name.

There is no way to dynamically set PHP values using a mouseover - you need to somehow submit data to the PHP page to get the data sent.

Just curious - if this page is a PHP page, why do you need to send the image src to the file? Isn't PHP what dynamically generates the image src anyway?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply