Specials | Announcements | About Us | Contact | Site Map
Willmaster.com
Hijack-proof forms. Surveys. List building.

Solid, safe website tools.

Whatever your need, Will Bontrager builds powerful software solutions.

Affiliate Cookie Setter
Search WillMaster.com:

WillMaster > Support > CGI Q&A

If you don't find the answer to your question in these archives, ask your CGI question at the Current Master Series CGI Forum.

Does this page provide information you can use?
     How can it be improved?
          Your comment is anonymous.
When done typing, click anywhere outside the box.     [more info]


Powered by "Real Time Reader Feedback" from WebSite's Secret.

calling cgi functions from onclick or javascript

Author Message
12Nov04

gwen-engineer
Subject: calling cgi functions from onclick or javascript

Hi, I'm a novice. I'm working on an "embedded webserver". Everything's got to be very simple. I have a form with the action being a cgi function. But I'd also like to have a button on the page that calls another cgi function. I don't want it to act like a submit button. I don't want to have to redraw the page or redirect. Thanks for you help, Gwen

12Nov04

Will

[Email]

In response to: calling cgi functions from onclick or javascript

To avoid redraw, you may need to go with JavaScript instead of CGI.

CGI, by definition, receives information from a browser and returns information to a browser. Information flows both ways.

The information sent to a browser is the content of a new web page to be displayed.

How CGI Works is a not-so-very technical overview of how CGI works.

12Nov04

gwen-engineer
In response to: calling cgi functions from onclick or javascript

Thanks for such a quick reply. I do want to get information from the browser to the server. I just don't want the page to disappear when I do. Can I do this with a javascript? Can a javascript call a cgi
function? If so can you give me an example so that I get the syntax correct.

13Nov04

Will

[Email]

In response to: calling cgi functions from onclick or javascript

When something is sent to the server using CGI, the server must send something back. Otherwise, you get an Internal Server Error because the CGI process couldn't be completed.

Three ways you might send something to a CGI program without having the browser re-load the page:

1.
If you can predict the click, and the information is available to send to the server when the page first loads, have the CGI script generate it's web page content output as JavaScript — using document.write() or document.writeln() functions.

The returned content might be put into a DIV layer with an "invisible" attribute.

2.
If you don't know what will be sent to the CGI program until after the page has been loaded, when it's time to send the information to the CGI program it might be done as an image request. A JavaScript function could create a new image class and then assign the SRC, the SRC being the URL to the CGI program with information sent as parameters.

3.
Use an IFRAME. When the CGI program is called, only the page in the IFRAME reloads.

There probably are other ways, too.