Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Simple question about function scope



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> JavaScript Forum
View previous topic :: View next topic  
Author Message
Drostin77



Joined: 27 Apr 2007
Posts: 2

PostPosted: Fri Apr 27, 2007 2:06 am    Post subject: Simple question about function scope Reply with quote

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.
Back to top
View user's profile Send private message
LucasZ21
100+ Club


Joined: 26 Feb 2007
Posts: 195
Location: Mansfield, OH

PostPosted: Wed May 02, 2007 3:33 am    Post subject: Re: Simple question about function scope Reply with quote

You don't really need a function in javascript to make an alert pop up.

Code:

<html>
<head>
<title></title>
</head>

<body>
<form>
<input type="button" onclick="alert('Hello World')" value="Hello World">
</form>
</body>

</html>


I don't know why your function would be comming up as undefined though. Hope I helped.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Drostin77



Joined: 27 Apr 2007
Posts: 2

PostPosted: Wed May 02, 2007 3:36 am    Post subject: Re: Simple question about function scope Reply with quote

Heh ya, i know i can do that. The alert is just to notify me that the function has even been called, the function actually needs to be a dynamically generated function each time that ajax page is loaded that populates drop downs with query data from a query who's parameters are dependant on the options they have chosen on the page before loading this div's ajax (i.e. from a form that is "submitted" via ajax (not an actual submit of course)). Thats why the code HAS to be in the page loaded via ajax.

Thank you for the answer though! your the first on like 4 forums to have answered, i think i phrased my question poorly.
Back to top
View user's profile Send private message
LucasZ21
100+ Club


Joined: 26 Feb 2007
Posts: 195
Location: Mansfield, OH

PostPosted: Wed May 02, 2007 4:55 pm    Post subject: Re: Simple question about function scope Reply with quote

Drostin77 wrote:
Heh ya, i know i can do that. The alert is just to notify me that the function has even been called, the function actually needs to be a dynamically generated function each time that ajax page is loaded that populates drop downs with query data from a query who's parameters are dependant on the options they have chosen on the page before loading this div's ajax (i.e. from a form that is "submitted" via ajax (not an actual submit of course)). Thats why the code HAS to be in the page loaded via ajax.

Thank you for the answer though! your the first on like 4 forums to have answered, i think i phrased my question poorly.


I thought you were just having trouble getting a messege to appear haha.

It might just be the way you wrote it...

Code:

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


I don't know if this matters but, when you declare a function, isn't there supposed to be a = sign and quotes around it?

Ex.
Code:
function = "foobar()"


Other than that I don't know.
Back to top
View user's profile Send private message Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> JavaScript Forum All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap