0

the requested page returns the following javascript by jsp:

<%!
String test = "hello world!!";
String test3 = "<script type=\"text/javascript\">document.getElementById(\"content\").setAttribute(\"style\",\"color:red\");</script>";
out.println(test3);
%>

and in the ajax page, i extracted the expression btw and uses

eval((e)())

in which e is the javascript returned, and the HTML is like:

<div id="content">
<p>hello world!</p></div>

but apparently the javascript returned does not work, is something wrong with the code? thanks by the way, i'm not allowed to use jQuery...

user2810081
  • 589
  • 1
  • 8
  • 27

1 Answers1

0

eval() takes in a single parameter: the Javascript code as a string, such as -

eval(e)

See http://www.w3schools.com/jsref/jsref_eval.ASP.

Prasad Silva
  • 1,020
  • 2
  • 11
  • 28
  • yes, i passed the javascript expression as a string to the eval(), but it doesn't work – user2810081 Mar 25 '14 at 21:00
  • What is the exact javascript expr you are trying to eval? – Prasad Silva Mar 25 '14 at 21:01
  • change the color of the element with id "content". – user2810081 Mar 25 '14 at 21:05
  • Assuming your expression is valid (you didn't post the -actual- JS only expr used with eval) and the HTML is valid, then it could be a browser issue: see http://stackoverflow.com/questions/6065609/document-getelementbyid-setattributestyle-not-working-in-internet-ex – Prasad Silva Mar 25 '14 at 21:10