Your JavaScript program is able to respond to user-initiated events (for example a form input). This happens without any network transmission.
JavaScripts are interpreted (not compiled) by the client.
Thus, when a user writes something into a form, it is not necessary that it be transmitted to the Server, verified and sent back, as with Perl. The input is verified by the client application and can be transmitted after that, if necessary.
Functions are called by user-initiated events, which are loaded first before a user can do anything that might call a function.
EXAMPLE:
<html> <head> <script language="LiveScript"> function pushbutton() { alert("Hello Karen!"); } </script> </head> <body> <form> <input type="button" name="Button1" value="Push me" onclick="pushbutton()"> </form> </body> </html>
So, what is going on in this script?
With server-based programs :
Servers were modified so that they could then start the CGI program specified in the form and pass the collected data to that program, which could, in turn, prepare a response (possibly by consulting a pre-existing database) and return a WWW document to the user.
The following diagram shows the various components of the process.
Taken from: http://kuhttp.cc.ukans.edu/info/forms/forms-intro.html
In this diagram, the Web client running on Computer A acquires a
form from some Web server running on Computer B. It displays the form,
the user enters data,
and the client sends the entered information to the HTTP server
running on Computer C.
There, the data is handed off to a CGI program which prepares a document and sends it to the client on Computer A. The client then displays that document.
The process is easier with Client-oriented software, like JavaScript.
With JavaScript you can check the data provided by the user before it is sent to the CGI program, saving valuable server resources.
For example, you can write a JavaScript function to verify that users enter valid information into a form requesting a telephone number or zip code. Without any network transmission, an HTML page with embedded JavaScript can interpret the entered text and alert the user with a message dialog if the input is invalid.
Assuming valid data is entered, when a Submit button is clicked, (or whatever the JavaScript looks for) JavaScript executes the specified method as in the alert method to Karen above.
At this time the data from the form is transmitted to the CGI program running on the server.
Verifying Form Input by Gordon McComb
JavaScript by Stefan Koch
ACKNOWLEDGEMENT: Much of the material on the page was written by Paul Leemans.
Send questions and comments to: Karen Lemone