Jump to content

Archived

This topic is now archived and is closed to further replies.

notonurnelly

Embedding PHP in HTML "'". '. ". problems

Recommended Posts

Hi all,

Just a quick question, Im sure it is very simple, I have a line of HTML code that calls a javascript function. The function basically scrolls layers. In order to scroll the javascript is sent a number of variable including in my case

A layer
and a value to scroll down to

the code below is a sample of the code which works.

onMouseOver="P7AniMagic('initial',0,-200,5,30,0,0)"

the two key values are the word initial and the -200.

the initial is the name of the layer I wish to scroll and -200 is by how much I wish to scroll.

for each of these I need to send values to in the form of variables so any layer can be scrolled any distance.

I can replace the -200 with the variable $ScrollVal

onMouseOver="P7AniMagic('initial',0,<?php echo $ScrollVal; ?>,5,30,0,0)"

this works fine, i then want to replace the layer name in the following way.

onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)"

This does not work, Im sure I have some of the "'". the wrong way around.

Can anyone tell me how this should be wrote for characters, I seem to have managed the numbers by the $ScrollVal variable working okay.

The full code for that line is below

<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>


Many Thanks
jamie


Share this post


Link to post
Share on other sites
Rather than going in and out of PHP mode. Use HEREDOC to echo out the HTML for the scroller:
[code=php:0]echo <<<SCROLLER
<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('{$Layer2Scroll}',0,{$ScrollVal},5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>
SCROLLER;
// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE![/code]

Share this post


Link to post
Share on other sites
hi
many thanks for your reply, I have never used that technique before. Wil lthis solve the problem I am having trying to get. Layer variable to be read as its value?

Many Thanks
Jamie

Share this post


Link to post
Share on other sites
Not sure but try the code out first and see if it works. However It should do. All I've done is taken your code and put it into a big echo statement.

Share this post


Link to post
Share on other sites
hi again wildteen

The page recgnised the echo, but again the layer did not scroll, its still the $layer2Scroll variable that is causing me problems, if I just replace the '{layer2scroll}'  with 'initial' its works fine.

So I still need to get the value of the variable to be read as text. What do you reckon.

Thanks
Again

Share this post


Link to post
Share on other sites
look page source in your browser
is it look OK?

Share this post


Link to post
Share on other sites
Hi Sasa

I cant tell, due to the fact that the function is in an external file, that is included. So when i view source i only get the info for that page i think.

onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
  <img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('',0,-2000,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">

altoguh i did find this code

Share this post


Link to post
Share on other sites
is it variable $Layer2Scroll set up
try change [code]<?php echo "'".$Layer2Scroll."'" ?>[/code]to[code]<?php $Layer2Scroll='initial'; echo "'".$Layer2Scroll."'" ?>[/code]if it works, check twice thet yuor variable have good value

Share this post


Link to post
Share on other sites
sasa

that worked okay,

thats when I set the variable within the code


<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php $Layer2Scroll='initial'; echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>

it also works when I do the below

$Layer2Scroll = "initial";

then

<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>

but will not work when I send the variable $Layer2Scroll to the whole function as below

function scroller_set($upval,$Layer2Scroll)
{
echo "Layer ".$Layer2Scroll;
$ScrollVal = $upval * -2000;

echo $scrollval;



?>
<div id="scroller" style="position:absolute; width:63px; height:23px; z-index:12; left: 774px; top: 275px; visibility: visible;"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic('initial',0,0,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)"><img src="images/del.jpg" width="31" height="31" onMouseOver="P7AniMagic(<?php echo "'".$Layer2Scroll."'" ?>,0,<?php echo $ScrollVal; ?>,5,30,0,0)" onMouseOut="P7AniMagic('initial',0,0,1,1,2,0)">
</div>
<?php
}


even though the echo statement

echo "Layer ".$Layer2Scroll;

is revealing

initial

I just dont get it, am I missing somethnig.

Thanks for your help i feel we are getting closer.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.