Lecture 2011 10 17
Forms
The form element groups together input elements; the data the user enters
is passed to the server (or can be 'passed' to Javascript code).
Between the <form> and </form>, you can place html tags (p, img, h1, etc).
Form tags:
- <form> Defines an HTML form for user input
- <input /> Defines an input control
- <textarea> Defines a multi-line text input control
- <label> Defines a label for an input element
- <fieldset> Defines a border around elements in a form
- <legend> Defines a caption for a fieldset element
- <select> Defines a select list (drop-down list)
- <optgroup> Defines a group of related options in a select list
- <option> Defines an option in a select list
- <button> Defines a push button
<form>
A form groups input values, and specifies where to pass the input values.
HTML tags and content can be interspersed among the various kinds of inputs
Attributes:
action
specifies where to pass form values:
- using
action
to specify URL of form handling code on client or on server
action = "my_action.php"
- using
action
mail the content TO YOURSELF ONLY UNTIL THOROUGHLY DEBUGGED
action="mailto:me@me.me"
This requires that the email client on the local machine be set up properly.
- nowhere -- just use the element ids to pass the data directly to your javascript code.
action="#"
Various event handlers. Here are some important ones for right now:
- onsubmit: Javascript code that is run before the code is submitted, with a submit button
- onreset: Javascript code that is run before the form's data is erased with a reset button
method
specifies how to send form-data. The form-handling code must
receive the data in an expected way.
The form-data can be sent as URL variables (method="get"
)
or as HTTP post (use method="post"
)
See w3schools
Getting user data
- Go through the input tag at w3schools
- button This is a good way to invoke Javascript
- checkbox
- text
- radio
- file
- submit (a button)
- reset (a button>
- image (another way to submit)
- password
- textarea
- label
- fieldset and
legend
- select and
optgroup
- button (versus the input type="button")
note, <button> does not have to go 'inside' a form
Note the use of Javascript's object.innerHTML