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.
Web Programming book reading for THIS class
form
Elementreset
and focus
MethodsBasic Form and Form Handler, version 2 (Heines)
Web Programming book reading for NEXT class
Same as for this class.
Questions from our last class or the readings or work between classes?
Source: https://gillencomputing.wordpress.com/2016/05/24/html-form-processing/
form
Element<form method="get" action="BasicForm_Handler.html"> ... form subelements go here ... </form>
method
attribute: get
vs. post
action
attribute
Source: Dean, Web Programming, p. 327, fig. 8.6
Additional form
Child Elements
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="range">
<input type="search">
<input type="tel">
<input type="time">
<input type="url">
<input type="week">
form
Submission Elements
<input type="submit"> =
a button that submits the form for processing<input type="reset"> =
a button that resets the form to its initial state<button>Button Text<button>
<input type="button" value="Button Text">
<input type="text" name="course" size="40" required>
name =
the name that will be passed to the search string along with
the control’s value when the form is submitted name="LastName"
and the user
types Heines
in the control, the URL will look something like:
http://cssdweb.edu/file.html?LastName=Heines
size =
width of the fieldplaceholder =
prompt to user inside the controlmaxlength =
maximum number of characters that can be enteredvalue =
initial text in the elementautofocus =
the element receives focus when the form is fully loadeddisabled =
the user is unable to give the control focus or copy or
edit its contentsreadonly =
the user can copy the control s content but not
edit itrequired =
indicates that the form cannot be submitted if this control
has no value<input type="text" id="lastname" name="course" size="40" required>
<input type="radio" name="timeslot" value="A">
name
attribute of all radio buttons intended to be mutually
exclusive must be the same<input type="number" name="room" min="1" max="10" step="1" value="">
min =
the minimum value that the control can havemax =
the maximum value that the control can havestep =
the change that will occur in the displayed value when the user
clicks the up or down arrow at the inside right of the control<select id="instructor" required> <option value="" selected disabled hidden>Choose an instructor</option> <option value="Daynard">Daynard</option> <option value="Heines">Heines</option> <option value="Spires">Spires</option> </select>
<input type="submit">
action
attribute is called to process the form form
tag can also have an onsubmit
attribute that
specifies a JavaScript function to be called before the
action is taken<form action="form-processor.html" onsubmit="return CheckForm();"
true
, the action is taken false
, the action is
not taken onsubmit
feture properly, the name of the
function to be called must be preceeded by return
value
attribute with the desired text<input type="submit" value="Process My Information">
<input type="reset">
value
attribute with the desired text<input type="reset" value="Start Over">
This example puts all of the above together:
Basic Form and Form Handler, version 2
Preamble: This is the same exercise that I introduced in our last class. I know that most students didn’t have enough time to work on it, so I’m hoping that at least some of you can get to it today.
Goal: To create a form and process the date that the user enters.
Procedure:
form
element with an action
attribute (the
value of the action
attribute can be the same page that contains
your form) input
control such as one with type="text"
Submit
button (<input type="Submit">
) Submit
button. Note the search string format. inupt
control to your form with a
different type
attribute Submit
button. Note the change in the search string.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" ) ] ;
action
attribute of your form
to
go to your new form processing page when the Submit
button is
clicked.
This is Class No. 21. 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.