473,762 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling functions from cgi

If I've loaded a set of functions in a webdocument like this:
<script language="JavaS cript" type="text/javascript"
src="/js/foo.js"</script>

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="JavaS cript" type="text/javascript">myf unction(myargs)
</script>

Even though it's generated from a CGI script? The all loaded javascript
files have the same scope do they not? It's not like the functions in
foo.js available only to other functions within that file? Right?
Jan 30 '06 #1
10 2474
Tony Rice wrote:
If I've loaded a set of functions in a webdocument like this:
<script language="JavaS cript" type="text/javascript"
Language is deprecated, drop it.

src="/js/foo.js"</script>

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="JavaS cript" type="text/javascript">myf unction(myargs)
</script>
Yes.
Even though it's generated from a CGI script? The all loaded javascript
What is generated from CGI - the script or the HTML document?

files have the same scope do they not? It's not like the functions in
foo.js available only to other functions within that file? Right?


Yes.

Do you get errors? What is the error message? Is the error because the
file isn't loaded, or because you are trying to manipulate objects in
the page before it's full loaded?
--
Rob
Jan 30 '06 #2
Tony Rice wrote:
If I've loaded a set of functions in a webdocument like this:
<script language="JavaS cript" type="text/javascript"
src="/js/foo.js"</script>
The language attribute is deprecated. You seem to have forgotten the ">"
from the opening script tag.
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="JavaS cript" type="text/javascript">myf unction(myargs)
</script>
Yes.
Even though it's generated from a CGI script?
How the server works out what to send to the user isn't relevant.
The all loaded javascript files have the same scope do they not? It's not
like the functions in foo.js available only to other functions within that
file? Right?


Right.

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jan 30 '06 #3
Tony Rice wrote:
If I've loaded a set of functions in a webdocument like this:
<script language="JavaS cript" type="text/javascript"
src="/js/foo.js"</script>

Shouldn't I be able to call a function from inside foo.js later in that
same document by doing something like this:
No, you need a ">" after: src="/js/foo.js"
Mick


<script language="JavaS cript" type="text/javascript">myf unction(myargs)
</script>

Even though it's generated from a CGI script? The all loaded javascript
files have the same scope do they not? It's not like the functions in
foo.js available only to other functions within that file? Right?

Jan 30 '06 #4
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="JavaS cript" 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="JavaS cript" type="text/javascript">myf unction(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.j s"></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.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 31 '06 #5
RobG <rg***@iinet.ne t.au> wrote in news:pkxDf.241$ Nv4.45834
@news.optus.net .au:
Do you get errors? What is the error message? Is the error because the
file isn't loaded, or because you are trying to manipulate objects in
the page before it's full loaded?


The errors I'm getting are DOM related. Wanted to make sure I was on the
right track before I dug anymore.

I'm trying to maintain state in a URL for a AJAX app. Make a element on
the page loadable via an ajax call or load automatically based on arguments
passed in the URL. But I'm getting DOM errors when I call the function
inline that is normally called from a user click.
Jan 31 '06 #6
Tony Rice wrote:
RobG <rg***@iinet.ne t.au> wrote in news:pkxDf.241$ Nv4.45834
@news.optus.net .au:

Do you get errors? What is the error message? Is the error because the
file isn't loaded, or because you are trying to manipulate objects in
the page before it's full loaded?

The errors I'm getting are DOM related. Wanted to make sure I was on the
right track before I dug anymore.

I'm trying to maintain state in a URL for a AJAX app. Make a element on
the page loadable via an ajax call or load automatically based on arguments
passed in the URL. But I'm getting DOM errors when I call the function
inline that is normally called from a user click.


That sounds like you are trying to access elements before the page has
created them, either onload or after the AJAX stuff.

Code snippet? URL? Did you fix the missing '>' from the closing script
tag noted in other responses?

--
Rob
Jan 31 '06 #7
RobG <rg***@iinet.ne t.au> wrote in news:zvBDf.251$ Nv4.46029
@news.optus.net .au:
That sounds like you are trying to access elements before the page has
created them, either onload or after the AJAX stuff.

Code snippet? URL?
I'm using jah (http://microformats.org/wiki/rest/ahah) to load URLs inline
dynamically. The perl script looks like this:

my $ajaxcall="jah( 'myotherscript. cgi?myarg=arg', 'contentdiv')";
if (param('myparam ')){
print "<script type=\"text/javascript\">$a jaxcall</script>\n";

}else{
print a({href=>"javas cript:$ajaxcall "}, 'click to load');
}
print "<div id='contentdiv' ></div>\n";

The goal is to have the content loaded inline automatically if the
'myparam' is passed in the query string and make it loadable inline by
clicking the link.
I'm getting the following errors:

document.getEle mentById(target ) has no properties

and

href has no properties
These are both coming from the ahah code. What I dont get is what is
special about the click. Either way it's accessing the document object so
it's not like the click is providing an object.

Any ideas?
Did you fix the missing '>' from the closing script
tag noted in other responses?


yes. That was a cut and paste error between the code and my newsreader.
Jan 31 '06 #8
Tony Rice wrote:
RobG <rg***@iinet.ne t.au> wrote in news:zvBDf.251$ Nv4.46029
@news.optus.net .au:

That sounds like you are trying to access elements before the page has
created them, either onload or after the AJAX stuff.

Code snippet? URL?

I'm using jah (http://microformats.org/wiki/rest/ahah) to load URLs inline
dynamically. The perl script looks like this:

my $ajaxcall="jah( 'myotherscript. cgi?myarg=arg', 'contentdiv')";
if (param('myparam ')){
print "<script type=\"text/javascript\">$a jaxcall</script>\n";

}else{
print a({href=>"javas cript:$ajaxcall "}, 'click to load');
}
print "<div id='contentdiv' ></div>\n";


Don't post server code, post what your client gets - this is a
JavaScript news group, not Perl :-)

What content is written to the script element? What is written as the
value of the A element's href attribute? What is the surrounding HTML?

I have no idea what is ending up in your A element attributes, so it's
hard to help. Use view source on the client to get the actual HTML that
is delivered to your page (a minimal test case will do).

The goal is to have the content loaded inline automatically if the
'myparam' is passed in the query string and make it loadable inline by
clicking the link.
I'm getting the following errors:

document.getEle mentById(target ) has no properties
The value of 'target' should be the ID of an element on your page. If
the page hasn't finished loading (unlikely), or the ID doesn't exist
(much more likely), then you will get the error you get.

The 'ahah' code does not test to see if features are supported, nor does
it check to see if document.getEle mentById(target ) returns anything
useful before trying to access its innerHTML property.


and

href has no properties

These are both coming from the ahah code. What I dont get is what is
special about the click. Either way it's accessing the document object so
it's not like the click is providing an object.


The click runs the script that is in the A element's href attribute. If
you show the client HTML, we can see what is actually in the href attribute.

--
Rob
Feb 1 '06 #9
RobG <rg***@iinet.ne t.au> wrote in
news:qG******** *********@news. optus.net.au:
Tony Rice wrote:
RobG <rg***@iinet.ne t.au> wrote in news:zvBDf.251$ Nv4.46029
@news.optus.net .au:

That sounds like you are trying to access elements before the page
has created them, either onload or after the AJAX stuff.

Code snippet? URL?

I'm using jah (http://microformats.org/wiki/rest/ahah) to load URLs
inline dynamically. The perl script looks like this:

my $ajaxcall="jah( 'myotherscript. cgi?myarg=arg', 'contentdiv')";
if (param('myparam ')){
print "<script type=\"text/javascript\">$a jaxcall</script>\n";

}else{
print a({href=>"javas cript:$ajaxcall "}, 'click to load');
}
print "<div id='contentdiv' ></div>\n";


Don't post server code, post what your client gets - this is a
JavaScript news group, not Perl :-)

What content is written to the script element? What is written as the
value of the A element's href attribute? What is the surrounding
HTML?

I have no idea what is ending up in your A element attributes, so it's
hard to help. Use view source on the client to get the actual HTML
that is delivered to your page (a minimal test case will do).


Sorry, thought it was obvious from that code snippet and it's important
to show how the javascript is generated differently depending on the
context.

The problem has been fixed by putting

<A HREF="javascrip t:jah('somethin g.cgi', 'contentdiv')>c lick to load</A>

inside <div id='contentdiv' > rather than outside.

I have no idea why this fixed it. This is the only change made but now
I'm getting no further errors from getElementById when calling the ahah
function directly.
The goal is to have the content loaded inline automatically if the
'myparam' is passed in the query string and make it loadable inline
by clicking the link.
I'm getting the following errors:

document.getEle mentById(target ) has no properties


The value of 'target' should be the ID of an element on your page. If
the page hasn't finished loading (unlikely), or the ID doesn't exist
(much more likely), then you will get the error you get.


I checked that angle out as well. didn't matter where the target div was
placed in relation ship to the ahah call.

Not sure why it works not, but at least it works.
Feb 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3232
by: pieter.breed | last post by:
Hi All, Is it possible to export a c# method into a dll in such a way that your "normal" C application can then call this method? To be clear: I am not asking how to use "DllImport" or PInvoke. My question is the other way around. Regards Pieter Breed
19
4260
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
5
2232
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its nitty gritty but its necessary for my program. thanks dave
1
1788
by: Mark Jerde | last post by:
Yesterday I posted the message below to microsoft.public.dotnet.languages.vb and microsoft.public.vc.language. The two replies are also posted. I need to write some ISO C++ functions, more information below. Is C# a better language to use than VB.NET for calling these C++ functions? If so I would appreciate some links on calling C++ from C#. Thanks! -- Mark
1
2914
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code written in C#. When the app calls my unmanaged functions, they work fine. But as soon as my unmanaged functions call managed functions (in the same source file!), the app reports an "unknown exception" error.
1
2603
by: H.B. | last post by:
Hi, I need to make a function that can display data on my Managed C++ app and be called by an unmanaged C++ DLL. Something like : void Form1::Form1_Load(System::Object * sender, System::EventArgs * e) { MyDLLInit(MyAppDisplayFunction); }
2
2816
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors, messages, etc: // If this parameter is NULL, // GetModuleHandle returns a handle of the file used // to create the calling process. hInstExe = GetModuleHandle( NULL ); if( hInstExe!=NULL )
18
4356
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I can use dlopen/whatever to convert the function name into a pointer to that function, but actually calling it, with the right number of parameters, isn't easy. As far as I can see, there are only two solutions: 1) This one is portable. If...
4
4801
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread completes it invokes a method from the calling thread. Sort event driven concept with threads. Thanks. Ed Gomez
10
3264
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a programming system places on how a procedure is called and how data is passed between a calling program and procedures are called calling conventions"
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9378
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7360
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.