/    Sign up×
Community /Pin to ProfileBookmark

Javascript in body not running

Hi,
I’m using YUI (asynchronous) and putting the response of my posted data in a div which is in the body of the HTML:

div.innerHTML = o.responseText;

However the javascript inside the responseText is not getting executed.

I have tried using the bubbling dispatcher plugin but this just removes the <script tags and the code inside the <script tags when I view the html source.

Instead I tried this bit of code passing in my div:

function evalScript(div) {

var x = div.getElementsByTagName(“script”);

var scriptBlocks = [];

for(var i=0; i<x.length; i++) {

var oScript = document.createElement(‘script’);

oScript.text = x[i].text;

scriptBlocks[i] = oScript;

}
for(var i=0; i <scriptBlocks.length; i++) {

div.appendChild(scriptBlocks[i]);

}
}

and this runs all the <script> //some code </script> tags in the div however it is not running any of the included scripts where I have lines like this:

<script type=”text/javascript” src=”aScriptFile.js”></script>

it just isn’t calling the file. I know the .js file(s) are ok because if I put them in the head of the HTML they do execute but I want to include these files dynamically in the body.

Any help would be great.
Thx

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@TeufelAug 18.2009 — Just return the response in javascript format and eval() it?

request.onSuccess = function(response) { return eval(response); }
Copy linkTweet thisAlerts:
@m_nhkauthorAug 18.2009 — thx Teufel, I've tried that by putting a eval around the response but I recieve a load of js errors because its trying to evalulate data that isn't being updated in that particular div and therefore falls over.

I think all I need is some kind of function that can pass an included <script type="text/javascript" src="aScriptFile.js"></script> in the page so it is visable through the browser
×

Success!

Help @m_nhk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...