Connecting Tech Pros Worldwide Help | Site Map

image swapping in php

Richard
Guest
 
Posts: n/a
#1: Jul 17 '05
I'm beginning to undertake php for the fun of it.

Working on a problem I hope can be solved in php.
Basically what I have is this:

<body>

<img name="main" src="image1.jpg">
<a href="#"
onMouseOver="document.main.src='image2.jpg'"
onMouseOut="document.main.src='image1.jpg'">one</a>

</body>

Ok I know, shoot me. I know "name" is not a valid attribute but it works.
If I use "ID" it does not work.

How would I go about converting this same effect to PHP?



Markus Ernst
Guest
 
Posts: n/a
#2: Jul 17 '05

re: image swapping in php


"Richard" <anom@anom> schrieb im Newsbeitrag
news:bm50kc0sgn@enews2.newsguy.com...[color=blue]
> I'm beginning to undertake php for the fun of it.
>
> Working on a problem I hope can be solved in php.
> Basically what I have is this:
>
> <body>
>
> <img name="main" src="image1.jpg">
> <a href="#"
> onMouseOver="document.main.src='image2.jpg'"
> onMouseOut="document.main.src='image1.jpg'">one</a>
>
> </body>
>
> Ok I know, shoot me. I know "name" is not a valid attribute but it works.
> If I use "ID" it does not work.
>
> How would I go about converting this same effect to PHP?[/color]

You can't do that. A mouseover event is processed at the client side (by the
browser); PHP runs at the server side.

If you understand that difference you will have much fun by making
Javascript (client side) and PHP (server side) work hand in hand.

--
Markus


Andy Hassall
Guest
 
Posts: n/a
#3: Jul 17 '05

re: image swapping in php


On Thu, 9 Oct 2003 20:04:58 -0500, "Richard" <anom@anom> wrote:
[color=blue]
>I'm beginning to undertake php for the fun of it.
>
>Working on a problem I hope can be solved in php.
>Basically what I have is this:
>
><body>
>
><img name="main" src="image1.jpg">
><a href="#"
> onMouseOver="document.main.src='image2.jpg'"
> onMouseOut="document.main.src='image1.jpg'">one</a>
>
></body>
>
>Ok I know, shoot me. I know "name" is not a valid attribute[/color]

No firearms required; it's perfectly valid. <img> does have a name attribute.

http://www.w3.org/TR/html4/struct/objects.html#h-13.2
[color=blue]
>How would I go about converting this same effect to PHP?[/color]

Once the HTML (or whatever you've output with PHP) has been sent to the
browser, PHP has no more involvement with what the user does, until there's
another request. So PHP cannot directly react to the user moving the mouse over
a part of the user interface of whatever browser they're using. The user would
have to click a link or submit a form for a pure PHP solution.

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Richard
Guest
 
Posts: n/a
#4: Jul 17 '05

re: image swapping in php


Andy wrote:
[color=blue]
> On Thu, 9 Oct 2003 20:04:58 -0500, "Richard" <anom@anom> wrote:[/color]
[color=blue][color=green]
>>I'm beginning to undertake php for the fun of it.[/color][/color]
[color=blue][color=green]
>>Working on a problem I hope can be solved in php.
>>Basically what I have is this:[/color][/color]
[color=blue][color=green]
>><body>[/color][/color]
[color=blue][color=green]
>><img name="main" src="image1.jpg">
>><a href="#"
>> onMouseOver="document.main.src='image2.jpg'"
>> onMouseOut="document.main.src='image1.jpg'">one</a>[/color][/color]
[color=blue][color=green]
>></body>[/color][/color]
[color=blue][color=green]
>>Ok I know, shoot me. I know "name" is not a valid attribute[/color][/color]
[color=blue]
> No firearms required; it's perfectly valid. <img> does have a name
> attribute.[/color]
[color=blue]
> http://www.w3.org/TR/html4/struct/objects.html#h-13.2[/color]
[color=blue][color=green]
>>How would I go about converting this same effect to PHP?[/color][/color]
[color=blue]
> Once the HTML (or whatever you've output with PHP) has been sent to
> the
> browser, PHP has no more involvement with what the user does, until
> there's
> another request. So PHP cannot directly react to the user moving the
> mouse over
> a part of the user interface of whatever browser they're using. The
> user would
> have to click a link or submit a form for a pure PHP solution.[/color]

Thanks. I found a way out of it and it even validates.
onmouseover="document.images[0].src='image2.jpg' "
onmouseout="document.images[0].src="image1.jpg' "


Alan Little
Guest
 
Posts: n/a
#5: Jul 17 '05

re: image swapping in php


Carved in mystic runes upon the very living rock, the last words of Richard
of comp.lang.php make plain:
[color=blue]
> Thanks. I found a way out of it and it even validates.
> onmouseover="document.images[0].src='image2.jpg' "
> onmouseout="document.images[0].src="image1.jpg' "[/color]

Just so you understand, that is JavaScript, not PHP.

Hmmm, an interesting idea, though: client-side PHP.

Nah!!!

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Daniel
Guest
 
Posts: n/a
#6: Jul 17 '05

re: image swapping in php


I have a PHP function in an include file that allows you to do this, but
in reality, all it does is output the code for the Javascript mouseover
effect... The rollover() function is copied below (with CppDoc
compatable documentation comment)

Cheers,
Daniel


-Snip-

/************************************************** ***************************
Creates a rollover button
@param $image_1 Name of the default image
@param $image_2 Name of the image to display when the mouse passes over
the image
@param $urllink Path or object that the text will be linked to
@param $ftarget Frameset target if used in a frame. If nothing is
specified, the target will not be used. If nothing is specified, and the
page is contained within a frame, the pane that contains the page that
uses this function will be replaced by the object defined in $linkpath.
@return Nothing
@since 1.0
************************************************** ***************************/
function rollover($image_1,$image_2,$urllink,$ftarget="")
{
if ($ftarget != "") {
$ftarget = " target=\"$ftarget\"";
}
echo <<<ROLLOVERHTML
<a href="$urllink"$ftarget onMouseOver= "if (document.images)
document.image1.src= '$image_2';" onMouseOut= "if (document.images)
document.image1.src= '$image_1';"><img src= "$image_1" name="image1"
border=0></a>
ROLLOVERHTML;

print("<script language=\"javascript\"><!-- if (document.images) { var
IMAGE1=new Image();IMAGE1.src=\"$image_2\";}//--></script>");
}

-Snip-

Richard wrote:[color=blue]
> I'm beginning to undertake php for the fun of it.
>
> Working on a problem I hope can be solved in php.
> Basically what I have is this:
>
> <body>
>
> <img name="main" src="image1.jpg">
> <a href="#"
> onMouseOver="document.main.src='image2.jpg'"
> onMouseOut="document.main.src='image1.jpg'">one</a>
>
> </body>
>
> Ok I know, shoot me. I know "name" is not a valid attribute but it works.
> If I use "ID" it does not work.
>
> How would I go about converting this same effect to PHP?
>
>
>[/color]

Closed Thread


Similar PHP bytes