Page 1 of 1

PHP onmouseover get image name.. ?

Posted: Tue Jun 28, 2005 7:25 pm
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.

Posted: Tue Jun 28, 2005 7:40 pm
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
-

Posted: Tue Jun 28, 2005 8:05 pm
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
?>

Posted: Tue Jun 28, 2005 10:33 pm
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.

Posted: Wed Jun 29, 2005 3:31 am
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.

Posted: Wed Jun 29, 2005 9:56 am
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?