Website Development I

Course Info Class Notes Resources Student Websites

Class No. 20:

Introduction to HTML Forms

Today’s Goal

To continue looking at the powerful things that one can do after one has set up a data structure, and to begin working with HTML forms.

We covered a huge amount of material in our last class.  Today we’re going to revisit and expand on the new topics we looked at.


Class Resources

Web Programming book reading for THIS class

Updated version of JavaScript Array Example 4d:  Defining and Sorting a Two‑Dimensional Array that uses a Wrapper function for the sort comparator (Heines)

Web Programming book reading for NEXT class

Same as for this class.


Preambles

How to pass parameters to a comparator function

// This approach "wraps" one function in another function.  Also note that the OUTER
// function returns the INNER function, further demonstrating that a function is simply
// a variable that contains executable code.
// adapted from:
//   

var Compare2DArrayColumn = function( nColumn ) {
  return function( a, b ) {
    a = a[nColumn] ;  // note the use of the parameter from the wrapper function
    b = b[nColumn] ;
    if ( a < b ) return -1 ;  // note that return terminates the function
    if ( a > b ) return +1 ;
    return 0 ;
  } ;
}

To call this function, use:

arrCSSD.sort( Compare2DArrayColumn( nSortColumn-1 ) ) ;
  // note the need to subtract 1 from the column number because array subscripts start at 0

Questions from our last class or the readings or work between classes?


Review:  Making Table Header Cells Responsive to Mouse Clicks

The onclick Attribute

The ReloadPage Function


Review:  Reading and Interpreting the Search String


Understanding How Forms Work

Client-Side vs. Server-Side Processing


Source:  https://gillencomputing.wordpress.com/2016/05/24/html-form-processing/

Form Example with Processing

This example provides a basic demonstration:

Basic Form and Form Handler, version 2


Today’s Exercise

Preamble:  I realize that most students will want to keep working on the exercise from our last class because we didn’t have enough time to work on that.  That’s fine.  I will not introduce new material in our next class, so you can work on this exercise then.

Goal:  To create a form and process the date that the user enters.

Procedure:

  1. Create an HTML file that contains a simple form.  Don’t try to get too fancy.  Start with just:
  2. Run your program and look at the URL that is generated when you click the Submit button.  Note the search string format.
  3. Add another inupt control to your form with a different type attribute
  4. Run your program again and look at the URL that is generated when you click the Submit button.  Note the change in the search string.
  5. Create a second HTML file the will process the data passed to it in the search string.  Follow the format of the code in the program that was introdued in our last class.
  6. let strSearch = window.location.search ;
    let urlParams = new URLSearchParams( strSearch ) ;
    let strRoomNumber = urlParams.get( "room" ) ;
    let strInstructorName = urlParams.get( "instructor" ) ;
    let strCourseTitle = urlParams.get( "course" ) ;
    let strTimeSlot = arrTimeSlots[ urlParams.get( "timeslot" ) ] ;
  7. Modify the action attribute of your form to go to your new form processing page when the Submit button is clicked.
  8. Test your program to see how the data entered into your form fields can ba processed by your form handler page.


 


This is Class No. 20.  It was last modified on Saturday, October 21, 2023 at 4:38 PM.  Copyright © 2010-2024 by Jesse M. Heines.  All rights reserved, but may be freely copied or excerpted for educational purposes with credit to the author.