Forum Moderators: open

Message Too Old, No Replies

use javascript to embed javascript in form

issues with </script> in enclosing <script>

         

jason_m

1:52 pm on Aug 18, 2010 (gmt 0)

10+ Year Member



hello,

i am unable to run the code below due to javascript interpreting the "</script>" as my actually closing the enclosing code, while rather it is referring to an internal code.

<html>
<head>


</head>

<body>
<textarea rows="20" cols="61" id="entry" name="entry" class="body_text" wrap="physical"></textarea>
<input type=button value="add image" onClick="AddPlot()" class="monobut">
</body>
</html>

<script>
function AddPlot(){
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 10;
var randomstring = '';
var rnum=0;
for (var i=0; i < string_length; i++) {
rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}

var plotter='';
plotter+=randomstring;
plotter+='<div id="chart1">';
plotter+='<div style="width: 390px; text-align: center; vertical-align: center; margin-top: 22px;"><a href="http://get.adobe.com/flashplayer/">';
plotter+='<img src="http://cdn.wikinvest.com/wikinvest/images/adobe_flash_logo.gif" alt="Flash" style="border-width: 0px;"/>';
plotter+='<br/>Flash Player 9 or higher is required to view the chart<br/><strong>Click here to download Flash Player now</strong>';
plotter+='</a>';
plotter+='</div>';
plotter+='</div>';
plotter+='<script type="text/javascript">if (typeof(embedWikichart) != "undefined") ';
plotter+='{embedWikichart("http://charts.wikinvest.com/WikiChartMini.swf","chart1","390","245",{"endDate":"17-08-';
plotter+='2010","showAnnotations":"true","ticker":"GOOG","liveQuote":"true","embedCodeDate":"2010-8-17","startDate":"17-02-2010"},{});}';
plotter+='</script>'; //ISSUE OCCURS HERE
plotter+='<div style="font-size:9px;text-align:right;width:390px;font-family:Verdana">';
plotter+='<a href="http://www.wikinvest.com/chart/GOOG" style="text-decoration:underline; color:#0000ee;">View the full NASDAQ:GOOG chart</a> at ';
plotter+='<a href="http://www.wikinvest.com/">Wikinvest</a>';
plotter+='</div>';

var MyElement = document.getElementById("entry");
MyElement.value +=plotter;*/

}
</script>

Fotiman

2:26 pm on Aug 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The / character needs to be escaped. Anywhere in your JavaScript code where you have a string with /, you should be escaping that with the \ character. As in:

plotter+='<br\/>Flash Player 9 or higher is required to view the chart<br\/><strong>Click here to download Flash Player now<\/strong>';
plotter+='<\/a>';
plotter+='<\/div>';
plotter+='<\/script>'; //ISSUE OCCURS HERE

etc.

jason_m

2:39 pm on Aug 18, 2010 (gmt 0)

10+ Year Member



ah Fotiman, thanks. totally brain-dead moment.
thanks