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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically generated JavaScript

Status
Not open for further replies.

portalguy123

Programmer
Sep 19, 2006
40
US
Hello Experts,

I am working on an AJAX application and I get a response back from the url which populates a div which has both HTML as well as JavaScript code , I need to extract the javascript from the response and set in the parent documnet's head tag so as to be able to acees the javascript in a global context.I use the following code to do so


Code:
extractAndProcess = function(windowObj,n){

    var re = /<script[\s\S]*?>([\s\S]*?)<\/scr/igm;
    var result = '';
    var match; 
    while (match = re.exec(responseString)) { 
     //document.write(match[1]);
     //eval(match[1]);
     result += match[1]; 
     //alert ('The match is '+match[1]);
   }
   
   alert('The result is '+result);
    
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.id = 'uploadScript';
   script.type = 'text/javascript';
   script.src = result;
   head.appendChild(script);
   
   alert('The set script is '+   document.getElementsByTagName("head")[0].value);
   populateEmailids(windowObj,n);
}

But when I print the value of teh head element I get a null back , can you please let me know where I might be wrong.

Thanks in Advance!!

-Bob F.
 
This is a cross-post of this thread: thread216-1295925. Please stick with one thread (presumably the one in the JS forum, as it appears to be more of a JS problem).

NB: It is "getElementsByTagName" you require.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top