/    Sign up×
Community /Pin to ProfileBookmark

Simple Javascript question (i think)

So i am developing in Coldfusion and asynchronous javascript . If i define a javascript function in my topmost page (the one in the url) any part of the page (a div who’s inner html has been populated by AJAC) can see that function. However, if one of these divs which has been populated by AJAC tries to define its own function, by having the following in its html

<script type=”text/javascript”>
function foobar() {
window.alert(“Hello World”);
}
</script>

and call that function via an onclick (or any other event) i get
Error: foobar undefined.

I have tried giving the script an id, and appending it as a child to the documents Head, i have tried appending its text to an existing script in the documents head who’s other functions work, foobar remains undefined. There is probably a simple fix, i probably phrased this poorly, please help if you can.

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Drostin77 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...