Module2.pdf
Document Details
Tags
Full Transcript
â€LEA‬ L†EARNING MODULE NO. 2‬ â€Title‬ â€HTML FORMS, GRAPHICS‬ â€Topic‬ †TML Form Elements, Input Types, Input Attributes, HTML‬ H â€Graphics Ca...
â€LEA‬ L†EARNING MODULE NO. 2‬ â€Title‬ â€HTML FORMS, GRAPHICS‬ â€Topic‬ †TML Form Elements, Input Types, Input Attributes, HTML‬ H â€Graphics Canvas & SVG‬ T†ime Frame‬ â€10 hrs.‬ â€Introduction‬ â€This module will introduce some html forms and graphics.‬ â€Objectives‬ â€At the end of this session, the students will be able to:‬ â€1.‬ â€Explain concept of html forms and graphics‬ â€2.‬ â€Familiarize the html form elements, type and attributes‬ â€3.‬ â€Describe the HTML graphics canvas and SVG‬ â€Learning Activities‬ â€HTML Forms‬ †n HTML form is used to collect user input. The user input is most often sent‬ A â€to a server for processing.‬ â€The Element‬ â€The HTML‬†‬â€element is used to create an HTML‬â€form for user input:‬ â€â€ ‬ â€.‬ †form elements‬ â€.‬ †‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 30‬ â€LEA‬ †he‬†T ‬â€element is a container for different types‬â€of input elements, such‬ â€as: text fields, checkboxes, radio buttons, submit buttons, etc.‬ †ll the different form elements are covered in the next chapter:‬â€HTML Form‬ A â€Elements‬â€.‬ â€The Element‬ â€The HTML‬†‬â€element is the most used form element.‬ †n‬†A ‬â€element can be displayed in many ways,‬â€depending on the‬†type‬ â€attribute.‬ â€Here are some examples:‬ â€Type‬ â€Description‬ â€â€¬ â€Displays a single-line text input field‬ â€â€¬ D †isplays a radio button (for selecting one of many‬ â€choices)‬ †input‬ < â€Displays a submit button (for submitting the form)‬ â€type="submit">‬ †input‬ < â€Displays a clickable button‬ â€type="button">‬ â€â€¬ †isplayes a file-select field and a "Browse" button for‬ D â€file uploads‬ â€All the different input types are covered in this chapter:‬â€HTML Input Types‬â€.‬ â€Text Fields‬ â€The ‬â€â€¬â€defines a single-line input‬â€field for text input.‬ â€Example‬ â€A form with two text input fields:‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 31‬ â€LEA‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ ††ote:‬â€The form itself is not visible. Also note that‬â€the default width of an input‬ N â€field is 20 characters.‬ â€The Element‬ â€Notice the use of the â€â€¬â€element in the example‬â€above.‬ â€The ‬â€â€¬â€tag defines a label for many form elements.‬ †he ‬â€â€¬â€element is useful for screen-reader users,‬â€because the‬ T â€screen-reader will read out loud the label when the user focus on the input‬ â€element.‬ †he ‬â€â€¬â€element also help users who have difficulty‬â€clicking on very small‬ T â€regions (such as radio buttons or checkboxes) - because when the user clicks‬ â€the text within the ‬â€â€¬â€element, it toggles the‬â€radio button/checkbox.‬ †he ‬â€for‬â€attribute of the â€â€¬â€tag should be equal‬â€to the ‬â€id‬â€attribute of‬ T â€the ‬â€â€¬â€element to bind them together.‬ â€Radio Buttons‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 32‬ â€LEA‬ â€The ‬â€â€¬â€defines a radio button.‬ â€Radio buttons let a user select ONE of a limited number of choices.‬ â€Example‬ â€A form with radio buttons:‬ ‬ †‬ †‬ †Male‬ †‬ †‬ †‬ †Female‬ †‬ †‬ †‬ †Other‬ †‬ †‬ †â€The Submit Button‬ †he ‬â€â€¬â€defines a button for submitting‬â€the form data to a‬ T â€form-handler.‬ †he form-handler is typically a file on the server with a script for processing‬ T â€input data.‬ â€The form-handler is specified in the form's â€a‬ ction‬â€attribute.‬ â€Example‬ â€A form with a submit button:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 33‬ â€LEA‬ â€â€ ‬ †‬ †â€Try it Yourself »‬ â€The Action Attribute‬ †he ‬â€action‬â€attribute defines the action to be performed‬â€when the form is‬ T â€submitted.‬ †sually, the form data is sent to a file on the server when the user clicks on the‬ U â€submit button.‬ I†n the example above, the form data is sent to a file called "action_page.php".‬ â€This file contains a server-side script that handles the form data:‬ ‬ †â€If the ‬â€action‬â€attribute is omitted, the action is‬â€set to the current page.‬ â€The Target Attribute‬ †he ‬â€target‬â€attribute specifies where to display the‬â€response that is received‬ T â€after submitting the form.‬ â€The ‬â€target‬â€attribute can have one of the following‬â€values:‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 34‬ â€LEA‬ â€Value‬ â€Description‬ â€_blank‬ â€The response is displayed in a new window or tab‬ â€_self‬ â€The response is displayed in the same frame‬ â€_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‬ †he default value is ‬â€_self‬â€which means that the response‬â€will open i the current‬ T â€window.‬ â€Example‬ â€Here, the submitted result will open in a new browser tab:‬ â€â€ < f ‬orm‬ â€action‬ ="/action_page.php"‬ †â€target‬ ="_blank">‬ †â€Try it Yourself »‬ â€The Method Attribute‬ â€The ‬â€method‬â€attribute specifies the HTTP method to‬â€use used when submitting the form data.‬ †he form-data can be sent as URL variables (with â€m‬ ethod="get"‬â€)‬â€or as HTTP post transaction‬ T â€(with ‬â€method="post"‬â€).‬ â€The default HTTP method when submitting form data is GET. ‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 35‬ â€LEA‬ â€Example‬ â€This example uses the GET method when submitting the form data:‬ â€â€ < f ‬orm‬ â€action‬ ="/action_page.php"‬ †â€method‬ ="get">‬ †â€Try it Yourself »‬ â€Example‬ â€This example uses the POST method when submitting the form data:‬ â€â€ < f ‬orm‬ â€action‬ ="/action_page.php"‬ †â€method‬ ="post">‬ †â€Try it Yourself »‬ â€Notes on GET:‬ â€â€¬ â€Appends the form data to the URL, in name/value pairs‬ â€â€¬ †EVER use GET to send sensitive data! (the submitted form data is visible in the URL!)‬ N â€â€¬ â€The length of a URL is limited (2048 characters)‬ â€â€¬ â€Useful for form submissions where a user wants to bookmark the result‬ â€â€¬ â€GET is good for non-secure data, like query strings in Google‬ â€Notes on POST:‬ â€â€¬ â€Appends the form data inside the body of the HTTP request (the submitted form data is not‬ â€shown in the URL)‬ â€â€¬ P †OST has no size limitations, and can be used to send large amounts of data.‬ â€â€¬ â€Form submissions with POST cannot be bookmarked‬ â€Tip:‬â€Always use POST if the form data contains sensitive‬â€or personal information!‬ â€The Name Attribute‬ â€Each input field must have a ‬â€name‬â€attribute to be‬â€submitted.‬ â€If the ‬â€name‬â€attribute is omitted, the value of that‬â€input field will not be sent at all.‬ â€Example‬ â€This example will not submit the value of the "First name" input field: ‬ ‬ †‬ †First name:‬ †‬ †‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 36‬ â€LEA‬ â€â€ < i ‬nput‬ â€type‬ ="submit"‬ †â€value‬ ="Submit">‬ †‬ †â€Try it Yourself »‬ â€Exercise:‬ â€In the form below, add an input field with the type "button" and the value "OK".‬ ‬ †â€â€¬ < >‬ †‬ †â€List of All Attributes‬ â€Attribute‬ â€Description‬ a†ccept-charse‬ â€Specifies the character encodings used for form submission‬ â€t‬ â€action‬ â€Specifies where to send the form-data when a form is submitted‬ â€autocomplete‬ â€Specifies whether a form should have autocomplete on or off‬ â€enctype‬ S†pecifies how the form-data should be encoded when submitting it to the server‬ â€(only for method="post")‬ â€method‬ â€Specifies the HTTP method to use when sending form-data‬ â€name‬ â€Specifies the name of the form‬ â€novalidate‬ â€Specifies that the form should not be validated when submitted‬ â€rel‬ â€Specifies the relationship between a linked resource and the current document‬ â€target‬ â€Specifies where to display the response that is received after submitting the form‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 37‬ â€LEA‬ â€HTML Form Elements‬ â€The HTML Elements‬ †he HTML â€â€¬â€element can contain one or more of‬â€the following form‬ T â€elements:‬ â€â€¬ â€input>‬ < â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€â€¬ ‬ †â€The Element‬ â€One of the most used form element is the ‬â€â€¬â€element.‬ †he ‬â€â€¬â€element can be displayed in several ways,‬â€depending on‬ T â€the ‬â€type‬â€attribute.‬ â€Example‬ â€â€ < l ‬abel‬ â€for‬ ="fname">‬ †First name:‬ †‬ †‬ †â€Try it Yourself »‬ †ll the different values of the â€t‬ ype‬â€attribute are‬â€covered in the next‬ A â€chapter: â€H ‬ TML Input Types‬â€.‬ â€The Element‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 38‬ â€LEA‬ â€The ‬â€â€¬â€element defines a label for several form‬â€elements.‬ †he ‬â€â€¬â€element is useful for screen-reader users,‬â€because the‬ T â€screen-reader will read out loud the label when the user focus on the input‬ â€element.‬ †he ‬â€â€¬â€element also help users who have difficulty‬â€clicking on very small‬ T â€regions (such as radio buttons or checkboxes) - because when the user clicks‬ â€the text within the ‬â€â€¬â€element, it toggles the‬â€radio button/checkbox.‬ †he ‬â€for‬â€attribute of the â€â€¬â€tag should be equal‬â€to the ‬â€id‬â€attribute of‬ T â€the ‬â€â€¬â€element to bind them together.‬ â€The Element‬ â€The ‬â€â€¬â€element defines a drop-down list:‬ â€Example‬ â€â€ < l ‬abel‬ â€for‬ ="cars">‬ †Choose a car:‬ †‬ †‬ †‬ †Volvo‬ †‬ †‬ †Saab‬ †‬ †‬ †Fiat‬ †‬ †‬ †Audi‬ †‬ †‬ †â€Try it Yourself »‬ â€The ‬â€â€¬â€elements defines an option that can be‬â€selected.‬ â€By default, the first item in the drop-down list is selected.‬ â€To define a pre-selected option, add the â€s‬ elected‬â€attribute‬â€to the option:‬ â€Example‬ â€â€ < o ‬ption‬ â€value‬="fiat"‬ †â€selected‬ >‬ â€Fiat‬ †‬ †â€Try it Yourself »‬ â€Visible Values:‬ â€Use the â€s‬ ize‬â€attribute to specify the number of visible‬â€values:‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 39‬ â€LEA‬ â€Example‬ â€â€ < l ‬abel‬ â€for‬ ="cars">‬ †Choose a car:‬ †‬ †‬ †‬ †Volvo‬ †‬ †‬ †Saab‬ †‬ †‬ †Fiat‬ †‬ †‬ †Audi‬ †‬ †‬ †â€Try it Yourself »‬ â€Allow Multiple Selections:‬ â€Use the â€m‬ ultiple‬â€attribute to allow the user to select‬â€more than one value:‬ â€Example‬ â€â€ < l ‬abel‬ â€for‬ ="cars">‬ †Choose a car:‬ †‬ †‬ †‬ †Volvo‬ †‬ †‬ †Saab‬ †‬ †‬ †Fiat‬ †‬ †‬ †Audi‬ †‬ †‬ †â€Try it Yourself »‬ â€The Element‬ â€The ‬â€â€¬â€element defines a multi-line input‬â€field (a text area):‬ â€Example‬ â€â€ < t ‬extarea‬ â€name‬="message"‬ †â€rows‬ ="10"‬ †â€cols‬ ="30">‬ †The cat was playing in the garden.‬ †‬ †â€Try it Yourself »‬ â€The ‬â€rows‬â€attribute specifies the visible number of‬â€lines in a text area.‬ â€The ‬â€cols‬â€attribute specifies the visible width of‬â€a text area.‬ â€This is how the HTML code above will be displayed in a browser:‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 40‬ â€LEA‬ â€You can also define the size of the text area by using CSS:‬ â€Example‬ â€â€ < t ‬extarea‬ â€name‬="message"‬ †â€style‬ ="width:200px; height:600px;">‬ †The cat was playing in the garden.‬ †‬ †â€Try it Yourself »‬ â€The Element‬ â€The ‬â€â€¬â€element defines a clickable â€b ‬ utton‬â€:‬ â€Example‬ â€â€ < b ‬utton‬ â€type‬ ="button"‬ †â€onclick‬ ="alert('Hello World!')">‬ †Click‬††Me!‬ ‬ †â€Try it Yourself »‬ â€This is how the HTML code above will be displayed in a browser:‬ †ote:‬â€Always specify the ‬â€type‬â€attribute for the button‬â€element. Different‬ N â€browsers may use different default types for the button element.‬ â€The and Elements‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 41‬ â€LEA‬ â€The ‬â€â€¬â€element is used to group related data‬â€in a form.‬ â€The ‬â€â€¬â€element defines a caption for the â€â€¬â€element.‬ â€Example‬ ‬ †‬ †‬ â€Personalia:‬ †‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The Element‬ †he ‬â€â€¬â€element specifies a list of pre-defined‬â€options for‬ T â€an â€â€¬â€element.‬ â€Users will see a drop-down list of the pre-defined options as they input data.‬ †he ‬â€list‬â€attribute of the ‬â€â€¬â€element, must refer‬â€to the â€i‬ d‬â€attribute of‬ T â€the ‬â€â€¬â€element.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 42‬ â€LEA‬ â€Example‬ ‬ †‬ †‬ †‬ ††< †‬‬option‬ †â€value‬="Firefox">‬ †‬ ††< †‬‬option‬ †â€value‬="Opera">‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The Element‬ †he ‬â€â€¬â€element represents the result of a calculation‬â€(like one performed‬ T â€by a script).‬ â€Example‬ â€Perform a calculation and show the result in an â€â€¬â€element:‬ â€â€ < f ‬orm‬ â€action‬ ="/action_page.php"‬ ††oninput‬ ="x.value=parseInt(a.value)+parseInt(b.value)">‬ ††0‬ ‬ ††100 +‬ ‬ ††=‬ ‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 43‬ â€LEA‬ â€HTML Form Elements‬ â€Tag‬ â€Description‬ â€â€¬ â€Defines an HTML form for user input‬ â€â€¬ â€Defines an input control‬ â€â€¬ â€Defines a multiline input control (text area)‬ â€â€¬ â€Defines a label for an element‬ â€â€¬ â€Groups related elements in a form‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 44‬ â€LEA‬ â€â€¬ â€Defines a caption for a element‬ â€â€¬ â€Defines a drop-down list‬ â€â€¬ â€Defines a group of related options in a drop-down list‬ â€â€¬ â€Defines an option in a drop-down list‬ â€â€¬ â€Defines a clickable button‬ â€â€¬ â€Specifies a list of pre-defined options for input controls‬ â€â€¬ â€Defines the result of a calculation‬ â€For a complete list of all available HTML tags, visit our â€H ‬ TML Tag Reference‬â€.‬ â€HTML Input Types‬ â€Here are the different input types you can use in HTML:‬ â€â€¬ â€input < type="button">‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 45‬ â€LEA‬ â€â€¬ â€input < type="month">‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€â€¬ ‬ â€Tip: The default value of the ‬â€type‬â€attribute is "text".‬ â€Input Type Text‬ â€defines a ‬â€single-line text input‬â€field‬â€:‬ ‬ †â€Example‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Password‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 46‬ â€LEA‬ â€defines a ‬â€password field‬â€:‬ ‬ †â€Example‬ ‬ †‬ †Username:‬ †‬ †‬ †‬ †Password:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The characters in a password field are masked (shown as asterisks or circles).‬ â€Input Type Submit‬ â€defines a button for â€s ‬ †‬ ubmitting‬â€form‬â€data to‬ â€a â€f‬ orm-handler‬â€.‬ †he form-handler is typically a server page with a script for processing input‬ T â€data.‬ â€The form-handler is specified in the form's â€a‬ ction‬â€attribute:‬ â€Example‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 47‬ â€LEA‬ I†f you omit the submit button's value attribute, the button will get a default‬ â€text:‬ â€Example‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Reset‬ â€defines a â€r‬ eset button‬â€that will‬â€reset all form values to‬ ‬ †â€their default values:‬ â€Example‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 48‬ â€LEA‬ â€Input Type Radio‬ â€defines a â€r‬ adio button‬â€.‬ ‬ †â€Radio buttons let a user select ONLY ONE of a limited number of choices:‬ â€Example‬ ‬ †‬ †‬ †Male‬ †‬ †‬ †‬ †Female‬ †‬ †‬ †‬ †Other‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Checkbox‬ â€defines a ‬â€checkbox‬â€.‬ ‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 49‬ â€LEA‬ †heckboxes let a user select ZERO or MORE options of a limited number of‬ C â€choices.‬ â€Example‬ ‬ †‬ †‬ †â€I have a bike‬ ‬ †‬ †‬ †â€I have a car‬ ‬ †‬ †‬ †â€I have a boat‬ ‬ †‬ †â€Try it Yourself »‬ â€Input Type Button‬ â€defines a â€b ‬ †‬ utton‬â€:‬ â€Example‬ â€â€ < i ‬nput‬ â€type‬ ="button"‬ †â€onclick‬ ="alert('Hello World!')"‬ †â€value‬ ="Click‬††Me!">‬ â€Try it Yourself »‬ â€Input Type Color‬ â€The ‬â€â€¬â€is used for input fields‬â€that should contain a color.‬ â€Depending on browser support, a color picker can show up in the input field.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 50‬ â€LEA‬ â€Example‬ ‬ †‬ †Select your favorite color:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Date‬ â€The ‬â€â€¬â€is used for input fields that‬â€should contain a date.‬ â€Depending on browser support, a date picker can show up in the input field.‬ â€Example‬ ‬ †‬ †Birthday:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€You can also use the â€m‬ in‬â€and â€m‬ ax‬â€attributes to add‬â€restrictions to dates:‬ â€Example‬ ‬ †‬ †Enter a date before 1980-01-01:‬ †‬ †‬ †‬ †Enter a date after 2000-01-01:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Datetime-local‬ †he ‬â€â€¬â€specifies a date‬â€and time input field, with no‬ T â€time zone.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 51‬ â€LEA‬ â€Depending on browser support, a date picker can show up in the input field.‬ â€Example‬ ‬ †‬ †Birthday (date and time):‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Email‬ †he ‬â€â€¬â€is used for input fields‬â€that should contain an e-mail‬ T â€address.‬ †epending on browser support, the e-mail address can be automatically‬ D â€validated when submitted.‬ †ome smartphones recognize the email type, and add ".com" to the keyboard‬ S â€to match email input.‬ â€Example‬ ‬ †‬ †Enter your email:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type File‬ †he ‬â€â€¬â€defines a file-select field‬â€and a "Browse" button for file‬ T â€uploads.‬ â€Example‬ ‬ †‬ †Select a file:‬ †‬ †‬ †‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 52‬ â€LEA‬ â€Try it Yourself »‬ â€Input Type Month‬ â€The ‬â€â€¬â€allows the user to select‬â€a month and year.‬ â€Depending on browser support, a date picker can show up in the input field.‬ â€Example‬ ‬ †‬ †Birthday (month and year):‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Number‬ â€The ‬â€â€¬â€defines a â€n ‬ umeric‬â€input‬â€field.‬ â€You can also set restrictions on what numbers are accepted.‬ †he following example displays a numeric input field, where you can enter a‬ T â€value from 1 to 5:‬ â€Example‬ ‬ †‬ †Quantity (between 1 and 5):‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Restrictions‬ â€Here is a list of some common input restrictions:‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 53‬ â€LEA‬ â€Attribute‬ â€Description‬ â€checked‬ †pecifies that an input field should be pre-selected when the pa S â€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‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 54‬ â€LEA‬ â€value‬ â€Specifies the default value for an input field‬ â€You will learn more about input restrictions in the next chapter.‬ †he following example displays a numeric input field, where you can enter a‬ T â€value from 0 to 100, in steps of 10. The default value is 30:‬ â€Example‬ ‬ †‬ †Quantity:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Range‬ †he ‬â€â€¬â€defines a control for entering‬â€a number whose exact‬ T â€value is not important (like a slider control). Default range is 0 to 100. However,‬ â€you can set restrictions on what numbers are accepted with the â€m‬ in‬â€, ‬â€max‬â€,‬ â€and â€s‬ tep‬â€attributes:‬ â€Example‬ ‬ †‬ †Volume (between 0 and 50):‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Search‬ †he ‬â€â€¬â€is used for search fields‬â€(a search field behaves like a‬ T â€regular text field).‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 55‬ â€LEA‬ â€Example‬ ‬ †‬ †Search Google:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Tel‬ †he ‬â€â€¬â€is used for input fields that‬â€should contain a telephone‬ T â€number.‬ â€Example‬ ‬ †‬ †Enter your phone number:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Time‬ â€The ‬â€â€¬â€allows the user to select‬â€a time (no time zone).‬ â€Depending on browser support, a time picker can show up in the input field.‬ â€Example‬ ‬ †‬ †Select a time:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 56‬ â€LEA‬ â€Input Type Url‬ â€The ‬â€â€¬â€is used for input fields that‬â€should contain a URL address.‬ †epending on browser support, the url field can be automatically validated‬ D â€when submitted.‬ †ome smartphones recognize the url type, and adds ".com" to the keyboard to‬ S â€match url input.‬ â€Example‬ ‬ †‬ †Add your homepage:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Input Type Week‬ â€The ‬â€â€¬â€allows the user to select‬â€a week and year.‬ â€Depending on browser support, a date picker can show up in the input field.‬ â€Example‬ ‬ †‬ †Select a week:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€Exercise:‬ â€In the form below, add an input field for text, with the name "username".‬ ‬ †â€â€¬ < >‬ †‬ †â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 57‬ â€LEA‬ â€HTML Input Type Attribute‬ â€Tag‬ â€Description‬ â€â€¬ â€Specifies the input type to display‬ â€HTML Input Attributes‬ â€This chapter describes the different attributes for the HTML ‬â€â€¬â€element.‬ â€The value Attribute‬ â€The input â€v‬ alue‬â€attribute specifies an initial value‬â€for an input field:‬ â€Example‬ â€Input fields with initial (default) values:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The readonly Attribute‬ â€The input â€r‬ eadonly‬â€attribute specifies that an input‬â€field is read-only.‬ †read-only input field cannot be modified (however, a user can tab to it,‬ A â€highlight it, and copy the text from it).‬ â€The value of a read-only input field will be sent when submitting the form!‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 58‬ â€LEA‬ â€Example‬ â€A read-only input field:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The disabled Attribute‬ â€The input â€d‬ isabled‬â€attribute specifies that an input‬â€field should be disabled.‬ â€A disabled input field is unusable and un-clickable.‬ â€The value of a disabled input field will not be sent when submitting the form!‬ â€Example‬ â€A disabled input field:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The size Attribute‬ †he input â€s‬ ize‬â€attribute specifies the visible width,‬â€in characters, of an input‬ T â€field.‬ â€The default value for ‬â€size‬â€is 20.‬ †ote:‬â€The ‬â€size‬â€attribute works with the following‬â€input types: text, search, tel,‬ N â€url, email, and password.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 59‬ â€LEA‬ â€Example‬ â€Set a width for an input field:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †PIN:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The maxlength Attribute‬ †he input â€m‬ axlength‬â€attribute specifies the maximum‬â€number of characters‬ T â€allowed in an input field.‬ †ote:‬â€When a ‬â€maxlength‬â€is set, the input field will‬â€not accept more than the‬ N â€specified number of characters. However, this attribute does not provide any‬ â€feedback. So, if you want to alert the user, you must write JavaScript code.‬ â€Example‬ â€Set a maximum length for an input field:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †PIN:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The min and max Attributes‬ †he input â€m‬ in‬â€and â€m‬ ax‬â€attributes specify the minimum‬â€and maximum values for‬ T â€an input field.‬ †he ‬â€min‬â€and â€m‬ ax‬â€attributes work with the following‬â€input types: number, range,‬ T â€date, datetime-local, month, time and week.‬ â€Tip:‬â€Use the max and min attributes together to create‬â€a range of legal values.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 60‬ â€LEA‬ â€Example‬ â€Set a max date, a min date, and a range of legal values:‬ ‬ †‬ †Enter a date before 1980-01-01:‬ †‬ †‬ †â€â€ ‬ †Enter a date after 2000-01-01:‬ †‬ †‬ †â€â€ ‬ †Quantity (between 1 and 5):‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The multiple Attribute‬ †he input â€m‬ ultiple‬â€attribute specifies that the user‬â€is allowed to enter more than‬ T â€one value in an input field.‬ â€The ‬â€multiple‬â€attribute works with the following input‬â€types: email, and file.‬ â€Example‬ â€A file upload field that accepts multiple values:‬ ‬ †‬ †Select files:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The pattern Attribute‬ †he input â€p‬ attern‬â€attribute specifies a regular expression‬â€that the input field's‬ T â€value is checked against, when the form is submitted.‬ †he ‬â€pattern‬â€attribute works with the following input‬â€types: text, date, search,‬ T â€url, tel, email, and password.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 61‬ â€LEA‬ â€Tip:‬â€Use the global â€t‬ itle‬â€attribute to describe the‬â€pattern to help the user.‬ â€Tip:‬â€Learn more about â€r‬ egular expressions‬â€in our JavaScript‬â€tutorial.‬ â€Example‬ †n input field that can contain only three letters (no numbers or special‬ A â€characters):‬ ‬ †‬ †Country code:‬ †‬ †‬ ‬ †â€Try it Yourself »‬ â€The placeholder Attribute‬ †he input â€p‬ laceholder‬â€attribute specifies short a‬â€hint that describes the expected‬ T â€value of an input field (a sample value or a short description of the expected‬ â€format).‬ â€The short hint is displayed in the input field before the user enters a value.‬ †he ‬â€placeholder‬â€attribute works with the following‬â€input types: text, search, url,‬ T â€tel, email, and password.‬ â€Example‬ â€An input field with a placeholder text:‬ ‬ †‬ †Enter a phone number:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The required Attribute‬ †he input â€r‬ equired‬â€attribute specifies that an input‬â€field must be filled out before‬ T â€submitting the form.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 62‬ â€LEA‬ †he ‬â€required‬â€attribute works with the following input‬â€types: text, search, url, tel,‬ T â€email, password, date pickers, number, checkbox, radio, and file.‬ â€Example‬ â€A required input field:‬ ‬ †‬ †Username:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The step Attribute‬ â€The input â€s‬ tep‬â€attribute specifies the legal number‬â€intervals for an input field.‬ â€Example: if step="3", legal numbers could be -3, 0, 3, 6, etc.‬ †ip:‬â€This attribute can be used together with the‬â€max and min attributes to‬ T â€create a range of legal values.‬ †he ‬â€step‬â€attribute works with the following input‬â€types: number, range, date,‬ T â€datetime-local, month, time and week.‬ â€Example‬ â€An input field with a specified legal number intervals:‬ ‬ †‬ †Points:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ †ote:‬â€Input restrictions are not foolproof, and JavaScript‬â€provides many ways‬ N â€to add illegal input. To safely restrict input, it must also be checked by the‬ â€receiver (the server)!‬ â€The autofocus Attribute‬ †he input â€a‬ utofocus‬â€attribute specifies that an input‬â€field should automatically‬ T â€get focus when the page loads.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 63‬ â€LEA‬ â€Example‬ â€Let the "First name" input field automatically get focus when the page loads:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The height and width Attributes‬ â€The input â€h‬ eight‬â€and â€w‬ idth‬â€attributes specify the‬â€height and width of an ‬â€â€¬ †â€element.‬ †ip:‬â€Always specify both the height and width attributes‬â€for images. If height‬ T â€and width are set, the space required for the image is reserved when the page‬ â€is loaded. Without these attributes, the browser does not know the size of the‬ â€image, and cannot reserve the appropriate space to it. The effect will be that‬ â€the page layout will change during loading (while the images load).‬ â€Example‬ â€Define an image as the submit button, with height and width attributes:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The list Attribute‬ †he input â€l‬ ist‬â€attribute refers to a ‬â€â€¬â€element‬â€that contains pre-defined‬ T â€options for an element.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 64‬ â€LEA‬ â€Example‬ â€An element with pre-defined values in a :‬ ‬ †‬ †‬ †‬ ††< †‬‬option‬ †â€value‬="Firefox">‬ ††< †‬‬option‬ †â€value‬="Chrome">‬ ††< †‬‬option‬ †â€value‬="Opera">‬ ††< †‬‬option‬ †â€value‬="Safari">‬ †‬ †‬ †â€Try it Yourself »‬ â€The autocomplete Attribute‬ †he input â€a‬ utocomplete‬â€attribute specifies whether‬â€a form or an input field should‬ T â€have autocomplete on or off.‬ †utocomplete allows the browser to predict the value. When a user starts to‬ A â€type in a field, the browser should display options to fill in the field, based on‬ â€earlier typed values.‬ †he ‬â€autocomplete‬â€attribute works with â€â€¬â€and the‬â€following ‬â€â€¬â€types: text,‬ T â€search, url, tel, email, password, datepickers, range, and color.‬ â€Example‬ â€An HTML form with autocomplete on, and off for one input field:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †Email:‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 65‬ â€LEA‬ †ip:‬â€In some browsers you may need to activate an‬â€autocomplete function for‬ T â€this to work (Look under "Preferences" in the browser's menu).‬ â€Exercise:‬ â€In the input field below, add placeholder that says "Your name here".‬ ‬ †â€input type="text" ‬ < >‬ †‬ †â€HTML Form and Input Elements‬ â€Tag‬ â€Description‬ â€â€¬ â€Defines an HTML form for user input‬ â€â€¬ â€Defines an input control‬ â€For a complete list of all available HTML tags, visit our â€H ‬ TML Tag Reference‬â€.‬ â€HTML Input form* Attributes‬ †his chapter describes the different †T ‬ orm*‬ f â€attributes‬â€for the‬ â€HTML ‬†‬â€element.‬ â€The form Attribute‬ â€The input â€f‬ orm‬â€attribute specifies the form the ‬â€â€¬â€element‬â€belongs to.‬ †he value of this attribute must be equal to the id attribute of the ‬ T â€element it belongs to.‬ â€Example‬ â€An input field located outside of the HTML form (but still a part of the form):‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 66‬ â€LEA‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †‬ †â€â€ < l ‬abel‬ â€for‬ ="lname">‬ †Last name:‬ †‬ †‬ †â€Try it Yourself »‬ â€The formaction Attribute‬ †he input â€f‬ ormaction‬â€attribute specifies the URL of‬â€the file that will process the‬ T â€input when the form is submitted.‬ â€Note:‬â€This attribute overrides the ‬â€action‬â€attribute‬â€of the â€â€¬â€element.‬ â€The ‬â€formaction‬â€attribute works with the following‬â€input types: submit and image.‬ â€Example‬ â€An HTML form with two submit buttons, with different actions:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The formenctype Attribute‬ †he input â€f‬ ormenctype‬â€attribute specifies how the‬â€form-data should be encoded‬ T â€when submitted (only for forms with method="post").‬ â€Note:‬â€This attribute overrides the enctype attribute‬â€of the â€â€¬â€element.‬ †he ‬â€formenctype‬â€attribute works with the following‬â€input types: submit and‬ T â€image.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 67‬ â€LEA‬ â€Example‬ †form with two submit buttons. The first sends the form-data with default‬ A â€encoding, the second sends the form-data encoded as "multipart/form-data":‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The formmethod Attribute‬ †he input â€f‬ ormmethod‬â€attribute defines the HTTP method‬â€for sending form-data to‬ T â€the action URL.‬ â€Note:‬â€This attribute overrides the method attribute‬â€of the â€â€¬â€element.‬ â€The ‬â€formmethod‬â€attribute works with the following‬â€input types: submit and image.‬ †he form-data can be sent as URL variables (method="get") or as an HTTP post‬ T â€transaction (method="post").‬ â€Notes on the "get" method:‬ â€â€¬ T †his method appends the form-data to the URL in name/value pairs‬ â€â€¬ â€This method is useful for form submissions where a user want to‬ â€bookmark the result‬ â€â€¬ â€There is a limit to how much data you can place in a URL (varies between‬ â€browsers), therefore, you cannot be sure that all of the form-data will be‬ â€correctly transferred‬ â€â€¬ â€Never use the "get" method to pass sensitive information! (password or‬ â€other sensitive information will be visible in the browser's address bar)‬ â€Notes on the "post" method:‬ â€â€¬ T †his method sends the form-data as an HTTP post transaction‬ â€â€¬ â€Form submissions with the "post" method cannot be bookmarked‬ â€â€¬ â€The "post" method is more robust and secure than "get", and "post" does‬ â€not have size limitations‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 68‬ â€LEA‬ â€Example‬ †form with two submit buttons. The first sends the form-data with‬ A â€method="get". The second sends the form-data with method="post":‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ ‬ †â€Try it Yourself »‬ â€The formtarget Attribute‬ †he input â€f‬ ormtarget‬â€a attribute specifies a name‬â€or a keyword that indicates‬ T â€where to display the response that is received after submitting the form.‬ â€Note:‬â€This attribute overrides the target attribute‬â€of the â€â€¬â€element.‬ â€The ‬â€formtarget‬â€attribute works with the following‬â€input types: submit and image.‬ â€Example‬ â€A form with two submit buttons, with different target windows:‬ ‬ †‬ †First name:‬ †‬ †‬ †‬ †Last name:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The formnovalidate Attribute‬ †he input â€f‬ ormnovalidate‬â€attribute specifies that‬â€an element should not‬ T â€be validated when submitted.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 69‬ â€LEA‬ â€Note:‬â€This attribute overrides the novalidate attribute‬â€of the â€â€¬â€element.‬ â€The ‬â€formnovalidate‬â€attribute works with the following‬â€input types: submit.‬ â€Example‬ â€A form with two submit buttons (with and without validation):‬ ‬ †‬ †Enter your email:‬ †‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€The novalidate Attribute‬ â€The ‬â€novalidate‬â€attribute is a â€â€¬â€attribute.‬ †hen present, novalidate specifies that all of the form-data should not be‬ W â€validated when submitted.‬ â€Example‬ â€Specify that no form-data should be validated on submit:‬ ‬ †‬ †Enter your email:‬ †‬ †‬ †‬ †‬ †â€Try it Yourself »‬ â€HTML Form and Input Elements‬ â€Tag‬ â€Description‬ â€â€¬ â€Defines an HTML form for user input‬ â€â€¬ â€Defines an input control‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 70‬ â€LEA‬ â€For a complete list of all available HTML tags, visit our â€H ‬ TML Tag Reference‬â€.‬ â€IT 413 – WEB SYSTEMS AND TECHNOLOGIES‬ â€RACABAÑERO 71‬