Web design2 Flashcards
HTML FORMS
An HTML form is used to collect user input
INPUT ELEMENT TYPE- form
input type=”text”> Displays a single-line text input field
input type=”radio”> Displays a radio button (for selecting one of many choices)
input type=”checkbox”> Displays a checkbox (for selecting zero or more of many choices)
input type=”submit”> Displays a submit button (for submitting the form)
input type=”button”> Displays a clickable button
https://www.w3schools.com/html/html_forms.asp
Structure of the form
form>
label for=”fname”>First name:</label><br></br>
input type=”text” id=”fname” name=”fname”><br></br>
label for=”lname”>Last name:</label><br></br>
input type=”text” id=”lname” name=”lname”>
</form
Label and for attribute-form
- The label> tag defines a label for many form elements.
- The label> element is useful for screen-reader users, because the screen-reader will read out loud the label when the user focuses on the input element.
- The label> element also helps users who have difficulty clicking on very small regions (such as radio buttons or checkboxes) - because when the user clicks the text within the label> element, it toggles the radio button/checkbox.
- The for attribute of the label> tag should be equal to the id attribute of the input> element to bind them together.
Radio buttons-form
Radio buttons let a user select ONE of a limited number of choices.
https://www.w3schools.com/html/html_forms.asp
Checkbox-form
checkboxes let a user select ZERO or MORE options of a limited number of choices.
https://www.w3schools.com/html/html_forms.asp
The Submit Button
The <input></input> defines a button for submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
The form-handler is specified in the form’s action attribute.
HTML form attributes
* Action: Defines the action to be performed when the form is submitted.Usually, the form data is sent to a file on the server when the user clicks on the submit button
Target: specifies where to display the response that is received after submitting the form.
_blank The response is displayed in a new window or tab
_self The response is displayed in the current window
_parent The response is displayed in the parent frame
_top The response is displayed in the full body of the window
framename The response is displayed in a named iframe
Method:attribute specifies the HTTP method to be used when submitting the form data.
The form-data can be sent as URL variables (with method=”get”) or as HTTP post transaction (with method=”post”).
The default HTTP method when submitting form data is GET.
HTML form elements
The HTML <form> element can contain one or more of the following form elements:
Tag Description
form> Defines an HTML form for user input
**input> **Defines an input control
textarea> Defines a multiline input control (text area)
label> Defines a label for an <input></input> element
fieldset> Groups related elements in a form
legend> Defines a caption for a <fieldset> element
**select> **Defines a drop-down list
optgroup> Defines a group of related options in a drop-down list
**option> **Defines an option in a drop-down list
button> Defines a clickable button
datalist> Specifies a list of pre-defined options for input controls
output> Defines the result of a calculation
https://www.w3schools.com/html/html_form_elements.asp
HTML input types
**input type=”button”>: **defines a button:
**input type=”checkbox”>: **Checkboxes let a user select ZERO or MORE options of a limited number of choices.
input type=”color”>
**input type=”date”>: **used for input fields that should contain a date.
**input type=”datetime-local”>: **specifies a date and time input field, with no time zone
input type=”email”>: is used for input fields that should contain an e-mail address.
**input type=”file”>: **defines a file-select field and a “Browse” button for file uploads.
**input type=”hidden”> **: defines a hidden input field (not visible to a user).
input type=”image”>:defines an image as a submit button.
**input type=”month”> : **allows the user to select a month and year.
input type=”number”>: defines a numeric input field
**input type=”password”>: **defines a password field:
input type=”radio”>: radio buttons let a user select ONLY ONE of a limited number of choices
**input type=”range”>: **defines a control for entering a number whose exact value is not important (like a slider control). Default range is 0 to 100.
**input type=”reset”>: **defines a reset button that will reset all form values to their default values:
input type=”search”> : is used for search fields
input type=”submit”>: efines a button for submitting form data to a form-handler.
input type=”tel”>: is used for input fields that should contain a telephone number.
input type=”text”>: defines a single-line text input field
input type=”time”> : allows the user to select a time (no time zone).
input type=”url”>: is used for input fields that should contain a URL address.
**input type=”week”>: ** allows the user to select a week and year.
https://www.w3schools.com/html/html_form_input_types.asp
HTML input types attributes
Attribute Description
**checked **Specifies that an input field should be pre-selected when the page loads (for type=”checkbox” or type=”radio”)
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
**maxlength **Specifies the maximum number of character for an input field
min Specifies the minimum value for an input field
pattern Specifies a regular expression to check the input value against
**readonly **Specifies that an input field is read only (cannot be changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
**value ** Specifies the default value for an input field
Placeholder: attribute specifies a short hint that describes the expected value of an input field (a sample value or a short description of the expected format).
Autofocus: attribute specifies a short hint that describes the expected value of an input field (a sample value or a short description of the expected format).
List: refers to a <datalist> element that contains pre-defined options for an <input></input> element. es como un select
**Autocomplete: ** allows the browser to predict the value. When a user starts to type in a field</datalist>
https://www.w3schools.com/html/html_form_attributes.asp
css form style
If you only want to style a specific input type, you can use attribute selectors:
- input[type=text] - will only select text fields
- input[type=password] - will only select password fields
- input[type=number] - will only select number fields
- Use the :focus selector to do something with the input field when it gets focus:
https://www.w3schools.com/css/css_form.asp
responsive forms
Resize the browser window to see the effect (the labels and inputs will stack on top of each other instead of next to each other on smaller screens)
https://www.w3schools.com/howto/howto_css_responsive_form.asp
Accessibility Forms
https://www.w3schools.com/accessibility/accessibility_forms_intro.php
HTML Validation tool
https://validator.w3.org/