Page 1 of 1

Question regarding text as a variable...

Posted: Wed Nov 23, 2005 12:48 am
by Staleycantrell
This is probably a pretty basic question, but I don't know much about PHP. I'm familiar with a few other languages, though, so I understand how variables and triggers work.

What I'm trying to do for my site is have a text variable set on the page, that will change based on when I tell it to.

Basically, what I'm doing is having a row of pictures, and mouse-overing one of them will display a description, using the text variable...

Is this possible with PHP?

Thanks for any help,

Scott

Posted: Wed Nov 23, 2005 12:54 am
by robster
Sounds like you might be better off looking for javascript to do the actual mouseover / textchange thing. You could feed the javascript with php though, if that's necessary.

Posted: Wed Nov 23, 2005 1:00 am
by Staleycantrell
I'm using wordpress to write my site, and it's all in PHP... Is it possible to insert javascript into a php format? I'm a bit of a noob when it comes to internet-based languages :/

Posted: Wed Nov 23, 2005 6:11 am
by Jenk
The first thing to understand about PHP is it is a Server side language. This means, even though your your page will have PHP code on it, and the user 'looks' at that page, the PHP code is not passed to the client.

This means that dynamic coding, such as you are asking for, cannot be done by PHP without communications between the user agent (client browser) and the server.

PHP's primary function in life is to generate output that is sent to the client, more specifically, it generates output that is interpreted by the client. This means that part of that output can be JavaScript, so you can dynamically generate JavaScript for your page and the Client's browser will interpret and if it is 'correct' run it :)



Now for your question - could you specify what, or rather where you want this text to appear?

If you want to appear in a 'balloon' box, then you can use the <img> alt attribute as most browsers will display this text when the user places their mouse cursor over the image. This is however not the intended use of the alt attribute, but is probably the most popular use. (It's intended use is as alternative text, i.e. text that is to be used when the picture cannot be displayed for whatever reason).

If you want the text to appear, say in a seperate <label> (for example) then you will need to use JavaScript to change the value of the <label> (i.e. DHTML).