How to replace the div content onclick?

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”);
so.write(“flashcontent”);
</script>
</div> ';

$ssk=‘SREE’;

?>
<!-- php code end –>

<html>
<head>
<script type=“text/javascript” src=“swfobject.js”></script>
<title>Change div content</title>

<style>
/* 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;}
</style>

<script>
function changeDivContent( nameOfDiv, newContent )
{
var div = document.getElementById( nameOfDiv );
if( div )
{
div.innerHTML = newContent;
}
}
</script>

</head>
<body>
<a href=“#” onclick=“changeDivContent( ‘scriptVars1’, ‘<? echo $ssk; ?>’ )”>Click here to change the content</a>

<div id=“scriptVars1”>
<br/><br/><br/><br/>
This content should be replaced…
</div>

</body>
</html>

Any help from this forum would be really appreciated.

Hi siva1117, welcome to the forums.
If you use

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

does the view-source look like

<a href="#" onclick="changeDivContent( 'scriptVars1', '<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");
so.write("flashcontent");
</script>
</div> ' )">Click here to change the content</a>

(*see how the syntax highlighter looks off?)
if so, try escaping the quotes ands semi-colons with backslashes. You may need to “double-escape” them to escape the escape character.

I tried backslashes but no use… here is the generated source…

<a href=“#” onclick=“changeDivContent( ‘scriptVars1’, '<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”);
so.write(“flashcontent”);
</script>
</div> ’ )”>Click here to change the content</a>

Unlike php, in javascript a string cannot span multiple lines in the source code.


// works
alert('hi there');

// error
alert('hi
 there');


// works
alert('hi \\
there');