USE HTML FORMS TO INTERACT WITH SCRIPTS

Take a quick look at a few details of the HTML forms code and see how it's used to interact with a script. The following is the forms code from the HTML page displayed in Figure 1-1:

<form action="artform.pl" method="post" name="form1">
  First Name:
<input name="text1" type="text" size="20"><br><br>
  Last Name:
<input name="text2" type="text" size="20"><br><br>
  Age:<br><br>
<input name="age" type="radio" value="1-17">
  1-17 yrs<br><br>
<input name="age" type="radio" value="18 and 
  over" checked>
18 yrs and over<br><br>
I would like to learn to work with:<br><br>
<input name="media1" type="checkbox"
  value="wc">watercolors<br>
<input name="media2" type="checkbox" 
  value="ac">acrylics<br>
<input name="media3" type="checkbox"
  value="pl">pastels<br><br>
<textarea name="interest" cols="50" rows="4">
  I am interested in art lessons 
  because:</textarea><br><br><br>
<input name="submit" type="submit" 
  value="Send me an application now!">
</form>

The first line of the form code includes an action attribute:

action="artform.pl"

This is the script that will execute to process the data that's submitted when the user clicks the Send me an application now! button. This script has a .pl file extension, which means that it's written in the Perl language. You'll be taking a closer look at Perl and other Web scripting and programming languages later in this lesson. Perl is one of many languages that can be used to process input data from HTML forms and send information back to the user via an HTML page.

Notice that most of the form elements include a name and a value attribute. The back-end script processes these name-value pairs and then sends the information as you've specified in the script: a database entry, an e-mail, or an HTML page.

The submit button is designed to send the information from the Web page to the script when the button is clicked. Clicking a button is an event . Because you can add actions to trigger scripts to run when events occur, buttons are used not only to submit forms data, but to also start any script that you've connected to that event. You'll be looking at events in detail in Lesson 6.

Scripting or Programming: What's the Difference? Good question! The distinction is a bit fuzzy because most scripting languages continue to develop additional capabilities that make the distinction even less clear. Here's one way to look at the difference: A scripting language needs another program, such as a Web browser. The browser actually runs the script when it reads the script code in an HTML page. Without an additional program, a computer can't run a script. A programming language is more independent; a computer can run the program without an additional program. Programming languages usually have additional features not available in scripting languages, such as classes in object-oriented programming languages such as C++ and Java. Scripting languages use variables, loops, conditionals, and other programming features, and has more in common with programming than differences. In the final analysis, scripting is programming -- a special type of programming, perhaps, but programming nevertheless.