473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

image swapping in php

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?

Jul 17 '05 #1
5 2939
"Richard" <anom@anom> schrieb im Newsbeitrag
news:bm********@enews2.newsguy.com...
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?


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
Jul 17 '05 #2
On Thu, 9 Oct 2003 20:04:58 -0500, "Richard" <anom@anom> wrote:
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
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
How would I go about converting this same effect to PHP?


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 (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #3
Andy wrote:
On Thu, 9 Oct 2003 20:04:58 -0500, "Richard" <anom@anom> wrote:
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 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 How would I go about converting this same effect to PHP?

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.


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' "
Jul 17 '05 #4
Carved in mystic runes upon the very living rock, the last words of Richard
of comp.lang.php make plain:
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' "


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/
Jul 17 '05 #5
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:
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?


Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: uNConVeNtiOnAL | last post by:
Hi - I have a page that has a button that makes a prompt appear for the user to type input. When they have typed in input, I want the button to change color when the prompt closes. I am...
3
by: Randell D. | last post by:
Folks, I'm still learning javascript - I've invested in a couple of books and reading online as much as possible. I'm pretty sure what I am suggesting is possible though I'm trying to weigh up...
8
by: TheKeith | last post by:
I'm doing an image cycler but can't figure out why it keeps getting hung up on the third pic in the array? Here is what I have: ...
8
by: OysterCracker | last post by:
Hi - I've previously used js to swap images on mouseover in a menu. I'm stumped on a different situation and would appreciate some advice. I would like to swap imageA to ImageB when I mouseover...
2
by: Richard | last post by:
www.somestuff.batcave.net/test1.html I have the major part of this monster worked out. Changing categories is fine. Only thing is, I get nothing when I click on a thumbnail. I know the value is...
6
by: cjl | last post by:
I have a website which allows people to view interesting radiology cases. It is for teaching radiology residents. It is designed to run in fullscreen or 'kiosk' mode, at 1024 x 768 resolution...
7
by: cjl | last post by:
OK: I am really scratching my head over a preload / image swapping problem, so I started conducting experiments: http://www.saintrays.net/experiment1.html...
5
by: Guadala Harry | last post by:
In an aspx page I have declared an Image control: <asp:Image id="myImage" runat="server"></asp:Image> In the code-behind I populate it's ImageURL property, like this: myImage.ImageUrl =...
2
by: guywmustang | last post by:
So, basically this is the problem. I have this... <div id="mainframe"> <img src="image.jpg" id="image"> </div> Then when I try to in a function say... function checkImage()
3
by: seamlyne | last post by:
The first method I ever used for multiple state buttons was to create a graphic for each button for each state: AboutUs_on, AbooutUs_over, AboutUs_out, etc. That works great when there are just a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.