I have one form, textarea & one button. On button click I call one php function. From that I call service to get data as per value inserted in textbox. function code is
function fire_btn(btnvalue) {
if(btnvalue=="Create Widget") {
var dataString = $("form").serialize();
receiveReq.open("GET", '<?php echo $this->config->item('url');?>getData/retriveData?&'+dataString);
receiveReq.onreadystatechange = getdata;
receiveReq.send(null);
document.getElementById('btnsave').value="Save Changes";
}
}
function getdata() {
if (receiveReq.readyState == 4 ) {
document.getElementById('code').innerHTML = receiveReq.responseText;
document.getElementById('codebox').focus();
}
}
Here Id "code" is my div id & Id "codebox" is d of my textarea.
Now in retriveData data function of php I am doing this
$x = "<input type='hidden' value='".$this->db->insert_id()."' name='hdn' id='hdn' />";
$x .= "<textarea id='codebox' readonly style='cursor:auto;min-width: 643px; min-height: 112px;max-width: 643px;max-height: 112px;margin-left:5px;'><!--Code Starts--><script type='text/javascript'>";
$x .= "wID= '".$this->db->insert_id()."';";
$x .= "document.write('<div id=myads".$this->db->insert_id()."></div>');";
$x .="document.write('<scr'+'ipt type=";
$x .='"text/JavaScript" src="'.$this->config->item('url').'allJs/myJs.js">';
$x .= "</scr'+'ipt>');</script><!--Code Ends--></textarea>";
echo $x;
myJs.js is
document.write('<link rel="stylesheet" type="text/css" href="style.css">');
document.write('<script type="text/javascript" src="http://myDomain.com/Create.js"></script>');
var myElement = document.getElementById('myads'+wID);
var JavaScriptCode = document.createElement("script");
JavaScriptCode.setAttribute('type', 'text/javascript');
JavaScriptCode.setAttribute("src", 'http://myDomain.com/content/'+wID);
document.getElementById('myads'+wID).appendChild(JavaScriptCode);
Now the problem is that in textarea text supposed to show is
<!--Code Starts--><div id='myads28'></div><script async type='text/JavaScript' charset='utf-8' src='http://myDomain.com/content/28'></script><!--Code Ends-->
this is properly shown when i test it in local machine
but when I see it on my hosted server it shows something like this.
<!--Code Starts--><script type='text/javascript'> wID= '28';document.write('<div id=myads28></div>');document.write('<scr'+'ipt type="text/JavaScript" src="http://myDomain.com/Create.js"></scr'+'ipt>');</script><!--Code Ends-->
I am not able to understand that what is happening.
can any one help me to solve it.
eval(document.getElementById('codebox').value);
done and done ;) – rlemon Aug 28 '13 at 19:02