Lab 8

Interactive Web Pages Using JavaScript and Forms

.
Script by: Robert Gasiorowski
Script only runs on Netscape 4.0 at the moment.

Table Of Contents:

Lab 8
Interactive Web Pages Using JavaScript and Forms
   Table Of Contents:
   Pre Lab:
      Goals for the Lab:
      Adding Human Interaction to the Web Page:
      Javascript Tutorials:
         Voodoo's JS Tutorial -- An Advanced JS Tutorial with a set of  Exciting Examples. This Tutorial Deals with some HTML 4.0 <layer> tag effects.
      Javascript Examples and Application Tutorials:
      Forms:
         The <FORM> Tag and Related Tags and Attributes
         The Form Tutorial
      Applications of Forms and Javascript Together
   Self Test of Lab Concepts:
   Example Pages for the Lab:
      Exercise 1 Example
      Exercise 2 Example
      Exercise 3 Example
      Exercise 4 Example
      Exercise 5 Example
   Lab 8 Instructions :
      Exercise 1: Our First Form using Email
      Exercise 2: The Next Form With a CGI
      Exercise 3: The Adding of JavaScript (JS) to our Form (Part 1)
      Exercise 4: The Adding of JavaScript (JS) to our Form (Part 2)
      Exercise 5: Creating a Page Using JS from the Web
   References:
      Glossary of New Terms:
      Related Tutorials:
      FAQ's:
      Other References:
Email

Pre Lab:

Goals for the Lab:

Adding Human Interaction to the Web Page:

The element of human interaction with the web page is necessary if the WWW is to be used as a means of creating E-commerce.  Gathering  market information, taking orders, and developing pages that attract viewers, and thus can be used to sell advertising,  requires forms.  The concept of a form, <form> and </form>, allows the viewer to supply information that can be sent from the viewer's computer (the client) to the web business (the server), which can process the data. The most common process uses a Common Gateway Interface (CGI), a program or script which can translate the data, enter it into a database, and create a HTML document.

Javascript is a limited scripting language that allows the web author to further extend the user's interactions and to make the document respond to user or computer events, such as clicking the mouse on a link, etc. The language Java, which was developed in the 1990's by Sun Computer, is a complete program language that adds further capability to the web page. Java and Javascript are not formally related and interactions between the two are limited. Java will be the subject of later lessons (See Lab  JavaProgramming for the Web).

This lab will investigate JavaScript (JS) and forms. The JS material will revisited in other labs as computer language requires more than a simple tutorial. This lab will introduce the basic concepts and ask the student to use scripts prepared by others via cut and paste. The tutorials and sample scripts will be examined and discussed to increase the student's familiarity with the language and its syntax.
 

Forms:

Forms were introduced into the HTML standard to allow the viewer (browser client) to interact with the Web server. Without this interaction the web site is of limited use to business, serving only as a billboard for posting notices and advertising. With the form on the client-side and CGI programs to capture the query and field a response, the CGI is frequently tied into the corporation's database and other necessary computer operations. A viewer can examine the corporation's catalogue of services and products, fill out an order, and the CGI can take the order, examine inventory levels, credit files, etc., prepare an invoice, ship the product, bill the credit card, and send a confirmation to the viewer. All this can occur in a few seconds or minutes allowing the viewer to select and purchase without leaving the home or office.

The <FORM> Tag and Related Tags and Attributes:

 
<Form></Form> Tag Attributes
Attribute Comment
Name= "String" Creates a name for the form object that is used by the JavaScript to reference this container and its related object (tags). See the discussion on javaScript objects.
Method= "Get| Post" The data in the tag container is either passed as a:
  • Get -- a message attached to the URL of the location where the information is to be processed. The attachement follows the usual URL starting with a "?" and followed by name and value pairs. Some special character information is encoded to allow the receiving location to distingush the operator characters from those used as normal text.
  • Post -- a file that is passed with the URL to where it will be sent to be processed.
Action= "URL|JavaScript" The location where the data is to be procressed:
  • URL of the CGI program that translates the form data as input for its own use or, as we shall see in later labs on dymanic web pages, creates a middleware request to applications located on the server.
  • Mailto -- creates an email that translates the form interaction into a message to the author, or to an email application program that transforms the user's interactions, i.e. takes an order.
  • JavaScript -- transforms the user's form inputs into an application, i.e creates a calculator, produces a recommendation, etc.
Enctype= "String" The browser must prepare the information for transmission to the server or application. The information is encoded in a manner that the server can parse (read). This action may involve transformation of come characters or symbols that have special meaning to the transfer process. After the information has been passed, the server or application has to unescape those characters that had to be translated. The string contains the name of the encoding.

Using the method Post versus Get:

From the description of the two allowed choices for the attribute method it maybe difficult to tell how to choose "Post" over "Get". In truth there is no major difference in selecting one or the other at the level of this material. In normal practice "Get" is often used in passing a small amount of  information (no more than 80 characters) from the client to the server. "Get" was developed first, and if one looks at the Location window in the browser after keying in a query to a search engine one will see something that looks like a normal URL typically ending in a path -- /cgi-bin/Program.Ext followed by a ? followed by your text query mixed in with some strange characters. The cgi-bin is the directory that contains the file Program.Ext that is to process your query. The "?" indicated to the web server that the remainder of the string is not part of the URL but a message to be processed by the Program. The first task that any CGI program has to do is to remove the encoding of the special characters back to their normal text format before parsing the message. The Post method takes the form's inputs and passes it through the Http protocol to the web server as a file and the CGI looks in the environmental variables of the Http and sees that the Post method was used and reads the form's data as normal input file.

Unless the exercise calls specifically for a Method ="get", all exercises will be based on the Method= "Post".
 

Encoding Type:

The encodings that are normally supported are:
 
 
The Commonly Supported Encoding Types
Encoding Type Comments
application/x-www-form-urlencoded This process translates spaces in the information to "+", non-alphanumeric data into % followed by a two digit hexadecimal that are the ASCII code for the symbol, and the line brakes as %0D%0A.
text/plain As the name implies, a simple text file.
multipart/form-data Allows the form's components, i.e. the type, send file, to be used to send a single MIME-compatible compound document. This is a fancy way of describing the familiar  email attachments.

 

Input Tag <input> an empty container-- a variety of means for inputting data:

Input Tag Attributes
Attribute Comments
Name The Name attribute names this instance of the input object for reference by JavaScript. Also when the Form is transmitted each of  its input containers are transmitted as "Name=Value" pairs where "value" is the string of information that is entered by either the Form or the viewer.
Type button-- creates a user defined button that can be used in place of the Submit button. Requires a JavaScript function to be defined.
checkbox -- a checkbox can be defined as Checked or Not Checked (blank), indicated by a rectangular box that when Checked has a Check character in it.
file -- Send a file to server/application, i.e. upload a file from the browser's client computer to the server/application.
hidden -- hidden data is a (Name=Value) pair that is not visible to the viewer through the display. Used to give the server further information, for instance the catalogue number and its expiration date.
image -- The image acts like a submit button when clicked. However, the image input also attaches two variables on the URL with the location of the cursor when clicked over the image, i.e.;

Name.x= NumberX&Name.y=NumberY. 

The NumberX and NumberY are in pixel coordinates. The name Name.x is used when Name is set. Otherwise it is simply x=NumberX.  Seldom used input type.

password --a text window where the message appears as "*" to the viewer and any onlookers. Note: password is not encrypted and hence, this offers only modest security for the viewer.
radio -- similar to Checkbox except all tags with the same "Name" attribute are treated as a group. Only one radio in the group may be selected (Checked). The radio is a circular window with a dot indicating it has been checked. If the viewer checks another radio in the group, then the first checked radio is deselected and the new checked radio will have a dot appear in its window.
reset -- reset is a button that can have a value, which will be the label on the button and whose action is to clear all the viewer's choices.
submit -- a special button that when clicked causes the Form's information to be transferred as per the <form> tag's method and action. The value is used to label the button with a custom message.
text -- creates a text window where the viewer can enter  information.
Value value -- The string (text) that, along with the name of the input tag, creates the (Name= Value) pair that is transferred using the Method and Action set in the <form> tag..
Size size -- the number of characters that can be viewed in the text window. This attribute only applies with the type text and password.
Maxlength The size of the maximum text message that can be entered in the text window.
Checked Is only meaningful with  Checkbox and Radio. When used with Radio only one member of group can be checked. When set in the tag it is the default, the viewer can select another radio or turn the checkbox to False ( turn Checked off). If no default the viewer selects the Checked element.

Examples of Input:

For the rest of the examples given on Form we will use the <Form> tag with: New material will be in red to allow the user to see the changes made from the prior example. Please click the Submit button. The Form's information will be sent to the web server and a CGI program called testform will echo back what it recieved from the Form.
 

 Examples <Input> types related to text:

Type = Text -- a text window for submitting an email address enabled by a Submit button:

In the example we use two input tags 1) the type = text where the text window length is 25 characters and we allow the maxlength to be 40 characters, 2) the type = "submit" is named Submit-Email and has a value= "Submit email address". By setting the Submit value attribute in this manner we can cue the viewer as to the nature of our request.
 
Example of a text used to request viewer's email address
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Text window to allow input of email address -->
<Input type="text" Name= "email" value=""size= "25" maxlength="40">

<Input type ="Submit" Name="Submit-Email" value="Submit email address">
</Form>

Alternative methods to cue the viewer as to what to fill in the text window:

In this case we set the value of the text input tag to value="Email Address" where it had previously been set to "" (a null string). The input value for the Submit was also set to "". In general, if the Form container is complicated with several input tags and/or select tags then it it is difficult to use the submit to cue the input.
 
Example of a text used to request viewer's email address with a cue in the text window.
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Text window to allow input of email address -->
<Input type="text" Name= "email" value="Email Address"size= "25" maxlength="40">

<Input type ="Submit" Name="Submit-Email" >
</Form>

Another method of cueing the query using normal text before, after, and below the text window.
 

Example of a text used to request viewer's email address with a text cue above, along side, and below..
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
Request EMail Address above<BR>
<!-- Text window to allow input of email address -->
<Input type="text" Name= "email" value=""size= "25" maxlength="40"> EMail Address<BR>

<Input type ="Submit" Name="Submit-Email" >
</Form>
Request EMail Address below<BR>

Request EMail Address above<BR>
EMail Address<BR>

Request EMail Address below<BR>

 

Input type="password" example:

Observe how the browser uses * for your text. However,  the CGI echos back your password unencrypted -- any sniffer (a program that listens to netrwork traffic) could also see it.
 
Example of Input type= Password used to request viewer's password.
HTML Source Code Display of the Source
<FORM  NAME="Password" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Text window to allow input of password Note this is not an encrypting submittion-->
<Input type="password" Name= "password" value=""size= "25" maxlength="40">

<Input type ="Submit" Name="Submit-Password" >
</Form>


 

Example <Input type= "hidden">:

The Hidden type is used to transfer additional information that is normally of use only to the CGI or application processing data and, while the information is not displayed, it is a good practice to minimize its use to informational text only, i.e. to text that is not actively processed or could be made into a security hole.
 
Example of Input type= Hidden used to label the course.
HTML Source Code Display of the Source
<FORM  NAME="hidden" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
Please Press the Submit there is nothing else to do.
<!-- In this example we have hidden the information from the user. Hence no text window appears. Normally hidden input is sent along with user input like name, address, etc.-->

<Input type="hidden" Name= "hidden" value="Course Exploring the Internet"size= "25" maxlength="40">

<Input type ="Submit" Name="Submit-Hidden Data" >
</Form>

Please Press the Submit there is nothing else to do.

Various forms of Input type buttons:

Example with <Input type= "Button">:

 
Example of a button "push button".
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Text window to allow input of email address -->
<Input type="button" Name= "ButtonTest" value="Click the Button"size= "25" maxlength="40" onClick= "Alert">

<Input type ="Submit" Name="Submit-Email" >
</Form>


Example with <Input type= "Image">:

This example reworks the original email address textbox. Here the type="image" works as a Submit button and the echo shows that the Image button also is similar to a server-side image map in that it sends the X and Y coordinates of the cursor where it was clicked over the image. This is a seldom used form of input.
 
Example of a text used to request viewer's email address
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Text window to allow input of email address -->
<Input type="text" Name= "email" value=""size= "25" maxlength="40">

<!-- Using an image as asubmit button and sending the X&Y coordinates of the click appended to the URL -->

<Input type ="Image"  src="submit.gif" Name="Submit-Email" value="Submit email address">
</Form>

Example <Input Type= "Reset"> -- Repeat the one of the Email text:

 
Example of a text used to request viewer's email address with a cue in the text window.
HTML Source Code Display of the Source
<FORM  NAME="email" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
Delete the email request cue and type in your email address. Click the Reset button. Note what happens. Retype your email address and submit.
<!-- Text window to allow input of email address -->
<Input type="text" Name= "email" value="Email Address"size= "25" maxlength="40">
<!-- Add a reset button to the prior email address example -->
<Input Type= "reset" Name= "email Reset" Value=
"reset bfore submitting">
<Input type ="Submit" Name="Submit-Email" >
</Form>
Delete the email request cue and type in your email address. Click the Reset button. Note what happens. Retype your email address and submit.

Checkbox and Radio Examples:

Checkbox example:

This Checkbox example allows the student to describe prior experience through prior practice and/or major field of study. Since a Checkbox is either checked or unchecked the options are not either/or. Hence the reader is free to check all that apply. The history of the source is that this is normally a first computer course for about 40 per cent of students, the default is set at very little prior experience. (see the Checkbox Name="Very Little"  has the attribute checked).
 
Example of a Checkbox to determine prior computer experience
HTML Source Code Display of the Source
<FORM  NAME="computer-experience" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Checkbox with Defaults --> 
What is your prior experience with Computers?<BR> 
<INPUT TYPE=CHECKBOX NAME="CSMajor" VALUE="YES" > CS Major<BR> 
<INPUT TYPE=CHECKBOX NAME="EEMajor" VALUE="YES"> EE Major<BR> 
<INPUT TYPE=CHECKBOX NAME="SCI_ENG_MGT" VALUE="YES" CHECKED> Science, Engineering, or Management Major<BR> 
<INPUT TYPE=CHECKBOX NAME="LiberalArts" VALUE="YES"> Non-Science Liberal Arts<BR> 
<INPUT TYPE=CHECKBOX NAME="Mus-Art" VALUE="YES"> Music or Arts Major<BR> 
<INPUT TYPE=CHECKBOX NAME="VeryLittle" VALUE="YES" CHECKED> Very Little<BR> 
<INPUT TYPE=CHECKBOX NAME="5yrs" VALUE="YES"> 5 or More Years of Computing<BR> 

<Input type ="Submit"  Name="Computer Experience" >
</Form>

What is your prior experience with Computers?
CS Major
EE Major
Science, Engineering, or Management Major
Non-Science Liberal Arts
Music or Arts Major
Very Little
5 or More Years of Computing

Radio Example:

In this Radio type example all of the input tags with the same name are grouped together and only one can be selected at any one time.
Clicking on one deselects the other. It is useful in either/or cases as in the example of year in school. If the majority of students in this class are supposed to have senior standing then the default Sr  could also have the attribute checked.
 
Example of a <Input type= "Radio"> -- Using class year as an example
HTML Source Code Display of the Source
<FORM  NAME="Class-Year" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
 

Year In School<BR> 

<!-- Radio Input Type allows only one answer --> 
<INPUT TYPE=RADIO NAME="Year_School" VALUE="Freshmen">FR. 
<INPUT TYPE=RADIO NAME="Year_School" VALUE="Sophmore">SP 
<INPUT TYPE=RADIO NAME="Year_School" VALUE="Junior">JR. 
<INPUT TYPE=RADIO NAME="Year_School" VALUE="Senior">SR.<BR> 

<Input type ="Submit" Name="Class Year" >
</Form>

Year In School
FR. SP JR. SR.

File Send example:

The File Send or what is actually a file upload to the server/CGI allows us to turn a form into a customer email application that allows attachment MIME file transfers from the client to the server.
 
Example of Input type= File 
Used to request the viewer to transfer a file from the viewer's client machine to the application.
HTML Source Code Display of the Source
<FORM  NAME="Send-A-File" METHOD=POST ACTION="http://holman.cs.uml.edu/~pkrolak/file_proc.php3" ENCTYPE="multipart/form-data">

<!-- Transfer a file from User's computer to the Server/Appication. Note this is not an encrypting. -->
<Input type="file" Name= "File-Transfer" >

<Input type ="submit" Name="Send File" >
</Form>


 
Example of Input type= File 
Used to request the viewer to transfer a file from the viewer's client machine to the Email application.
HTML Source Code Display of the Source
<FORM  NAME="Send-A-File" METHOD=POST ACTION="mailto:pkrolak@valinet.com" ENCTYPE="multipart/form-data">

<!-- Transfer a file from User's computer to the Server/Appication. Note this is not an encrypting. -->
<Input type="file" Name= "File-Transfer" >

<Input type ="submit" Name="Send File" >
</Form>

<Textarea></Textarea> Tag -- A Two Dimensional text window:

A textarea is a two dimensional text window, i.e. it allows for multiple rows of text and is very often used where a simple line of text is inappropriate.
For instance, asking the viewer for comments on service or remarks about the web site should allow for more than a simple it was not good, or it is ok. The textarea invited the viewer to give a full and thoughtful answer to a question. The texbox container uses its text contents  as a default text remark to occuppy the textarea window. Treat the Name attribute as a required element. The rows and columns if not defined do not have an established default. Thus, unless the author is truely indifferent to the textarea's appearance from one browser to another, the author should treat the attributes Rows and Cols as required.
 
Attributes of the <textarea></textarea> Tag Container
Attribute Commnets
Name the name of the textarea instance of the textarea objects.
Rows Rows -- the number of lines of text that appear in the textarea.
Cols Columns -- the number of characters that will appear in the texbarea window in each line.





 

Textarea example:

 
Example of a textarea for collection of multi line comments
HTML Source Code Display of the Source
<FORM  NAME="student" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<Textarea Name="student-comments" rows ="5" cols="30">PLACE YOUR REMARKS HERE </Textarea>

<Input type ="Submit" Name=Submit-student>
</Form>


 

<Select></Select> Tag -- Select an item from a menu:

The <Select></Select> container defines a pop up menu or scrolling list. The viewer either over rides the Slected option by clicking on their choice or allows the chosen default if any. If the viewer picks a new option the Selected attribute is reset to match the viewer's choice. If the Multiple attribute is chosen then, the viewer can select multiple choices. Depending on the browser the viewer may be required to use the [Shift] or [Ctrl] key to get the appropriate multiple selections. Treat the Name attribute as a required element. The <Option></Option> containers are the only allowed tags inside the <Select></Select> container and are used to define the options that the viewer may chose.
 
Attributes of the <Select></Select> Tag Container
Attribute Commnets
Name The name of the instance of the Select object
Size Size -- the number of options displayed in the window at one time. If the number of options exceeds the size then the window will be a scrolling list. If Size not defined then it will act as pop up menu.
Multiple If this attribute is used it allows multiple options to be selected at one time. Multiple is not tied to Size.




<Option>Defines options for the <Select></Select> Container

 
Attributes of the <Option>Tag Container
Attribute Comments
Value Value is the information to sent if selected. It does not have to be the same information that appears to the viewer in the text in the <Option></Option> container.
Selected This attribute allows the author to select the default option






Examples of  <Select></Select> for chosing items from scrolling lists or pop up menus:

A Pop Up Menu Example:

In this example the Select container has no Size attribute and defaults to a pop up menu. In this example the author does not default any option to avoid leading the reader. Note that while in this example the text that the viewer saw was indetical to what was sent to the server is often not the case. There is no reason for the value being sent to match the descriptive text
 
Example of a <Select></Select> as a pop up menu to determine course attitude
HTML Source Code Display of the Source
<FORM  NAME="class_attitude" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">

<!-- Select acts as a Popup Menu--> 
What are your Feelings for Exploring the Internet?<BR> 
<SELECT NAME="Course_Attitude" >
<OPTION VALUE="OK">OK 
<OPTION VALUE="Fun">Fun 
<OPTION VALUE="Interesting">Interesting 
<OPTION VALUE="Hard">Hard 
</SELECT><BR> 
 

<Input type ="Submit"  Name="Class Attitude" value="Submit -- student's 
                   class attitude">
</Form>

What are your Feelings for Exploring the Internet?

Example as a Select Scrolling window:

Observe the Size attribute is now set to Size="4". This generates a scrolling window that will allow all of the options to be seen in the smaller window. This is the way e-Commerce sites use the slect tag to locate inforamtionlike country and state.

The first option addres the viewer by -- Frst Name is Sleected as the default choice. Note also how the message is sent to the server. So not all things are not as they appear on the surface. Clearly this is a jarring example for the sake of  making a point.

A more appropriate example -- we might ask, -- what lab by title or number the viewer wanted to go to, and set the value of the option to the URL of the lab. Then when the viewer clicked the submit button they would be sent to the web page of the choosen lab.

Note the slected default appears with the black text against a blue background.
 

Example of using <Select></Select> tag as a scrolling window to determine --
how a viewer wants to be formally addressed
HTML Source Code Display of the Source
<FORM  NAME="viewer-title" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
Please Select the title to be used in class to used for formal address.
<!-- Selector with Size attribute set to "4" to act like a scrolling window--> 
<SELECT NAME="Title" SIZE=4> 
<OPTION VALUE="hates authority" Selected>First Name only
<OPTION VALUE="Ms">Ms. 
<OPTION VALUE="Mr.">Mr. 
<OPTION VALUE="Dr.">Dr. 
<OPTION VALUE="Officer">Officer 
<OPTION VALUE="Coach">Coach 
<OPTION VALUE="Prof.">Prof. 
<OPTION VALUE="Dean">Dean
</SELECT><BR>

<Input type ="Submit" Name=Submit-your title of address>
</Form>

Please Select the title to be used in class to used for formal address.


 

Example -- How do you want to be addressed  with Select allowing  Multiple  choices:
 

Example of using <Select></Select> tag as a scrolling window to determine --
Alternatives on how  viewer  wants to be addressed
Chose as many as apply use the [Mosue] and [Ctrl] for each choice!!
HTML Source Code Display of the Source
<FORM  NAME="viewer-title" METHOD=POST ACTION="http://www.cs.uml.edu/cgi-bin/testform" ENCTYPE="application/x-www-form-urlencoded">
Please Select the title(s) to be used in class to used when being addressed. Chose all that may apply and instructor will chose the appropriate one..
<!-- Selector with Size attribute set to "4" to act like a scrolling window--> 
<SELECT NAME="Title" SIZE=4 Multiple> 
<OPTION VALUE="hates authority" Selected>First Name only
<OPTION VALUE="Ms">Ms. 
<OPTION VALUE="Mr.">Mr. 
<OPTION VALUE="Dr.">Dr. 
<OPTION VALUE="Officer">Officer 
<OPTION VALUE="Coach">Coach 
<OPTION VALUE="Prof.">Prof. 
<OPTION VALUE="Dean">Dean
</SELECT><BR>

<Input type ="Submit" Name=Submit-your title of address>
</Form>

Please Select the title(s) to be used in class to used when being addressed. Chose all that may apply and instructor will chose the appropriate one..


 

Constructing a Simple Form:

The Design of Forms -- More art than science:

See also:
Chapter 14: "FormDesign and Data Gathering with CGI Scripts"http://media.njit.edu/~asim/books/HTML_by_example/ch14.htm

An Introduction to JavaScript:

A quick visit to a Javascript overview:

This is a Power Point presentation and has been designed with a 10 second automatic advance. Down load and store the file and set to advance on click or set timer to 15-30 second advances for a more careful introduction.
 Introduction to Javascript (JSTutorial.ppt)

The JavaScript Object Hierarchy:

JavaScript Object Hierarchy
   A Comprehensive JS Tutorial

A Javascript Refenece Site:

http://www.devguru.com/Technologies/ecmascript/quickref/js_methods.html

 This JS tutorial is by the University of Idaho ACM Student Chapter

Review of JS Events and samples scripts on how to use them.
In the U. of Idaho's Award winning ACM site is an excellent discussion of the various eventhandlers that are supported by JS. An event handler is associated with a tag. Not all event handlers are associated with all tags so read the section carefully. Also note that JS is CASE SENSITIVE hence a frequent source of error is mistaking the correct event handler onClick with onClick, or ONCLICK,etc. BE CAREFUL!!

For a review of Event handlers vs the HTML Tags that they can be used with.
These tables are taken from the above source and summarizes the major results.

Event Handlers Of Special Interest :


 
 

Introduction to Regular Expressions:

 A short tour of a very powerful tool for pattern matching

Debugging tools for JavaScript:

Visit and download the JavaScript debugger. http://developer.netscape.com/software/jsdebug.html

Javascript Examples and Application Tutorials:

 This site is designed for cut and paste of JavaScript; Students will need to visit this site and select their programs before class.

This Site has Many different JS that can be used in the Final Project

Some Simple javaScripts that add information and interaction to the web page:

Applications of Forms and Javascript Together:

Building a simple clock:
Building a simple calendar:
Building a calculator:

Validation of Forms (client Side) before Submission

Validate a Name

 
Validate a Name
  • A Name is one or more words.
  • A word is a string of one or more letters or special characters
  • A name may have a special characters ". -," 

  • Examples are:
    Dr. Susan Smith
    P. D. Brady
    Jones, Allen
    Prof. Robert Smythe-Smoot
<SCRIPT LANGUAGE= "JavaScript">
// function isString checks a string to see if it is made up of only letters and //special allowed characters. Else it retuns false meaning invalid.
<!--
function isString(textObj) {
var newValue = textObj.value
var newLength = newValue.length
var extraChars=". -,"
var search
for(var i = 0; i != newLength; i++) {
 aChar = newValue.substring(i,i+1)
 aChar = aChar.toUpperCase()
 search = extraChars.indexOf(aChar)
 if(search == -1 && (aChar < "A" || aChar > "Z") ) {
return false
}
  }
return true
}
//-->
</SCRIPT>

Validate an Integer Number

Validate A Integer Number
 
Validate an Integer Number Algorithm
  • An integer is a whole number, i.e. composed of all digits 
  • It is non-null, that is, it has at least one digit
<SCRIPT LANGUAGE= "JavaScript">
<!--
function isInt(textObj) {
  var newValue = textObj.value
  var newLength = newValue.length
  for(var i = 0; i != newLength; i++) {
aChar = newValue.substring(i,i+1)
if(aChar < "0" || aChar > "9") {
return false
}
}
return true
}
//-->
</SCRIPT>
Source:JavaScript Unleashed 2nd. Code simply checks for digits and reports false if a non digit is found

A quick introduction to the Common Gateway Interface (CGI):


Self Test of Lab Concepts:

 
Website Abstraction's Pop Quiz JS
CS 113 Quiz for the Form and Javascript Lab
by P. D. & M. S. Krolak
Solution:
Your response:
Start Over Cheat Mode

Example Pages for the Lab:

Exercise 1 Example

Exercise 2 Example

Exercise 3 Example

Exercise 4 Example

Exercise 5 Example

Lab 8: Exercises for creating and using interactive forms and javaScripts:

Exercise 1: Our First Form using Email

The inspiration for this exercise comes from a forms tutorial. You should visit this site and pay close attention to Lesson One and the note at the bottom of Lesson 4, which details how to create a form that uses the Mailto: method to send data back to the server.

We will make only two small changes to these instructions:

You will create, as in Lesson One, a "form1.html". However, this "form1.html" will correct one point--that the example does not work when there is no input to the Form. We have used examples from Lessons One-Five to construct a form that exhibits all the major features of the <Form>, <Input>, and <Select> Tags.

Exercise 2: The Next Form With a CGI


 

References:

Wagner, Richard, et. al., " Javascript Unleashed 2nd Edition", Sams.net, Indianapolis (1997).
Moncur, Micheal "SAMS Teach Yourself JavaScript in 24 Hours  2nd Edition", Sams.net, Indianapolis (2000).

Introduction to Netscape's JavaScript Debugger

Netscape's JavaScript Guide Manual (includes Javascript 1.2)

Netscape's JavaScript Reference Manual

Object Hierarchy and Inheritance in JavaScript

Glossary of New Terms:

CGI -- Common Gateway Interface (CGI) a server side program that receives inputs from the client side web page. These inputs are then processed on the server such a database application and a response is normally send back to the viewer.

Form -- a set of tags that allows the web page to request and interact with the viewer to gather data, perform an action or task, and/or send the data on to a server
.
Javascript -- a scripting language that is interpreted into a simple program at the time the web page is loaded to allow the author to create interactions based on a limited set of events that are defined for JavaScript's objects.

Related Tutorials:

Forms Tutorials:

  1. Carlos' Form Tutorial -- http://robot0.ge.uiuc.edu/~carlosp/cs317/ft.ref.html An excellent tutorial including a self test.
  2. Joe Barta's Forms Tutorial -- http://junior.apk.net/~jbarta/tutor/forms/index.html
  3. The <FORM> Tag and Related Tags and Attributes -- http://www.intergalact.com/hp/part2/tags.html
  4. CGI Tutorial

JavaScript Tutorials:

CGI Tutorials:
 Programming tutorials for the non-programmers -- http://www.easy-database.com/cgi/start.html

Try this Interactive Tutorial Laboratory to rapidly become a JavaScript programmer

FAQ's:

Other References:

Netscape JS Form Validation
More JS Goodies



 


©P.D.Krolak & M.S.Krolak 2001 All Rights Reserved

Email