Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic javascript not working in IE

Status
Not open for further replies.

KhalidAn

Programmer
Sep 20, 2007
3
US
My dynamic JS not working in IE. It is keep failing on line
newElem.innerHTML = theScript;
where theScript=alert('Hello'); which I get back from my AJAX call.
I had to go with the following workaround because javascript passed with AJAX contents was not working. Now following works ok in netscape but fails in IE.



function LoadJS(theScript)
{
var newElem = document.createElement("script");
var elemJS = document.getElementById("dinamicJScontainer");


newElem.setAttribute("language","JavaScript1.2");
newElem.setAttribute("type","text/javascript");
//IE is failing on following line.
newElem.innerHTML = theScript;
elemJS.appendChild(newElem);


};

where theScript=alert('hello');
 
your dynamic javascript is not working anywhere. most likely, alert('hello') is simply being called where you're setting the variable (incorrectly).

i suppose you could try [tt]theScript = [red]"[/red]alert('hello')[red]"[/red];[/tt], but I'm not sure of what you're trying to do, so I can only guess.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
the alert('hello'); is string so it is enclosed with "". Here is how I call LoadJS function.

var scriptEle = document.getElementById('scriptFromAjax')
if(scriptEle!=null){
LoadJS(scriptEle.innerHTML);
}

where scriptFromAjax is following.
<script id="scriptFromAjax">
alert('hello');
</script>
 
Perhaps this thread will help you out. I somehow got a star for the post, I guess the OP felt bad after he abandoned the thread *shrug*

thread1600-1404727

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Thank you so much. I looked all over the net and could was unable to find this answer. I wish this solution is on google search results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top