View Full Version : How to replace the div content onclick?

08-09-2008, 09:27 PM
Here is my script..
This works perfectly if the call the variable $ssk in the html, but it is not working when i call the variable $cvb.

Please help me out...

<!-- php code start -->

$cvb='<div id="flashcontent">
<script type="text/javascript">
var so = new SWFObject("player.swf", "sree", "635", "240", "9", "#E7E7E7");
so.addVariable("p_list", "try.xml");
so.addParam("allowFullScreen", "true");
</div> ';


<!-- php code end -->

<script type="text/javascript" src="swfobject.js"></script>
<title>Change div content</title>

/* this is just to add color and look :-)*/
div, a { padding:3px; margin:3px 3px 33px 3px; }
#scriptVars1 { border:1px solid red; width:635px; height:240px; background-color:#EEE;}

function changeDivContent( nameOfDiv, newContent )
var div = document.getElementById( nameOfDiv );
if( div )
div.innerHTML = newContent;

<a href="#" onclick="changeDivContent( 'scriptVars1', '<? echo $ssk; ?>' )">Click here to change the content</a>

<div id="scriptVars1">
This content should be replaced...


Any help from this forum would be really appreciated.

08-10-2008, 06:14 PM
because unlike php javascript does not allow multi-line literal strings...so, if u remove all the line breaks in $cvb and echo it out it should work fine

08-10-2008, 07:17 PM
Hi i tried removing all the line breaks, i even tried the backslash method but nothing seems to work....

all i need is to fire a JavaScript in the variable position... $cvb

08-10-2008, 08:27 PM
it's because you used all those double qoutes you probably need something more like this because if you echo double quotes into into your function it will mess things up.

$cvb="<div id='flashcontent'>
<script type='text/javascript'>
var so = new SWFObject('player.swf', 'sree', '635', '240', '9', '#E7E7E7');
so.addVariable('p_list', 'try.xml');
so.addParam('allowFullScreen', 'true');
</div> ";

Though if you're worried about semantics you could set $cvb to a JavaScript varible before