Re: calling functions from cgi
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: calling functions from cgi

From: Randy Webb <HikksNotAtHome@aol.com>
Date: Tue Jan 31 2006 - 00:49:43 CET

Tony Rice said the following on 1/30/2006 6:11 PM:
> If I've loaded a set of functions in a webdocument like this:
> <script language="JavaScript" type="text/javascript"
> src="/js/foo.js"</script>

Drop the language attribute though.

> Shouldn't I be able to call a function from inside foo.js later in that
> same document by doing something like this:
>
> <script language="JavaScript" type="text/javascript">myfunction(myargs)
> </script>

Yes, that is exactly how you would do it, but drop the language attribute.

> Even though it's generated from a CGI script?

The script engine in the browser doesn't know, nor does it care, what
generated the script contents.

> The all loaded javascript files have the same scope do they not?

They have the same scope as if you manually included them in the page,
which is what the browser does.

<script type="text/javascript" src="myJSFile.js"></script>

And if myJSFile.js had a function in it like this:

function myFunction(){
alert('This is an alert');
}

That function will have the same "scope" as if you did this:

<script type="text/javascript">
function myFunction(){
alert('This is an alert');
}
</script>

> It's not like the functions in foo.js available only to other
> functions within that file? Right?

Correct.

-- 
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Received on Tue Feb 7 21:28:10 2006