Tag is one of the versatile form elements and allows you to create different interface elements and provide user interaction. Mainly is designed to create text fields, various buttons, radio buttons and checkboxes. Although the element does not need to be placed inside the container
Options
Description of tag parameters
ALIGN parameter
Determines how to align the image field with text or other form elements.
Syntax
Arguments
- bottom- Align the bottom border of the image with the surrounding text
- left- Aligns the image to the left of the window
- middle- Alignment of the middle of the image to the baseline of the current line.
- right- Aligns the image to the right edge of the window.
- top- The top border of the image is aligned with the highest element of the current line.
The default is bottom. Browsers also support arguments absbottom, absmiddle, baselineand texttopwhich are not included in the HTML 4.01 specification.
ALT parameter
The alt parameter sets the alternative text for the image field. This text allows you to get text information about a picture when loading images is disabled in the browser. Since images are loaded after the browser receives information about them, the text replacing the image appears earlier. And already as it loads, the text will be replaced by an image. Browsers also display alternative text as a tooltip that appears when the mouse hovers over the image.
Syntax
The value can be any suitable text string... It must be enclosed in double or single quotes.
BORDER parameter
Browsers handle images added via the tag like pictures created with the tag ... Including around the image, you can add a frame, the color of which matches the color of the text.
Syntax
Valid value is any positive integer number in pixels. The default is 0.
CHECKED parameter
This parameter determines whether a form element such as a checkbox or radio button is pre-marked. In the case of using radiobuttons, only one element of the group can be checked; for checkboxes, it is permissible to mark at least all elements.
Syntax
DISABLED parameter
Blocks access and modification of the form field. In this case, it is displayed gray and unavailable for activation by the user. In addition, such a field cannot receive focus by pressing the Tab key, with the mouse, or in any other way. However, this state of the field can be changed using scripts.
Syntax
MAXLENGTH parameter
Sets maximum number characters that can be entered by the user in the text box. When this number is reached during dialing, no further input is possible.
Syntax
NAME parameter
Specifies a unique name for the form element. Typically, this name is used when sending data to the server or to access the entered field data through scripts.
Syntax
The name is a set of characters, including numbers and letters. JavaScript is case sensitive, so when referring to an element by name, use the same spelling as for the name parameter.
READONLY parameter
When to tag the readonly parameter is added, the text field cannot be changed by the user, including entering new text or modifying the existing one. In addition, such a field cannot receive focus by pressing the Tab key, with the mouse, or in any other way. However, the state and content of the field can be changed using scripts.
Syntax
SIZE parameter
The width of the text box, which is determined by the number of characters in the monospaced font. In other words, the width is set by the number of adjacent letters of the same horizontal width. If the font size is changed using styles, the width also changes accordingly.
Syntax
Valid value is any positive integer.
SRC parameter
The address graphic fileto be displayed on the web page in the image field.
Syntax
The value is the full or relative path to the file.
TYPE parameter
The required type parameter tells the browser what type the form element is.
Syntax
Arguments
- button- Button.
- checkbox- Flags. Allows you to select more than one option from the proposed ones.
- file- Field for entering the name of the file that is sent to the server.
- hidden- Hidden field. It is not displayed in any way on the web page.
- image- Image field. When you click on the picture, the form data is sent to the server.
- password- Normal text field, but different from it in that all characters are shown with asterisks. It is designed so that no one can see the entered password.
- radio- Switches. They are used when one should choose one of several options offered.
- reset- Button to return the form data to its original value.
- submit- Button for sending form data to the server.
- text- Text field. Designed for entering characters using the keyboard.
The default is text.
VALUE parameter
Specifies the value of a form element to be submitted to the server or received using client scripts. A pair "name \u003d value" is sent to the server, where the name is specified by the name parameter of the tag and the value is specified by the value parameter.
The value parameter plays the following role depending on the element type:
- for buttons (input type \u003d "button | reset | submit") sets a text caption on them;
- for text fields (input type \u003d "password | text") specifies the previously entered string. The user can erase the text and enter their characters, but when used in the form of the Reset button, the user text is cleared and the entered in the value parameter is restored;
- for checkboxes and radio buttons (input type \u003d "checkbox | radio"), uniquely identifies each element so that the client or server program can uniquely identify which item the user has selected.
Specification
Required attribute
The values
Table 1 lists the possible values \u200b\u200bof the type attribute and the resulting form of the form field.
A type | Description | View |
---|---|---|
button | Button. | |
checkbox | Checkboxes. Allows you to select more than one option from the proposed ones. | Beer Tea Coffee |
file | Field for entering the name of the file that is sent to the server. | |
hidden | Hidden field. It is not displayed in any way on the web page. | |
image | Image field. When you click on the picture, the form data is sent to the server. | |
password | A regular text field, but different from it in that all characters are shown with asterisks. It is designed so that no one can see the entered password. | |
radio | Switches. They are used when one should choose one of several options offered. | Beer Tea Coffee |
reset | Button to return the form data to its original value. | |
submit | Button for sending form data to the server. | |
text | Text field. Designed for entering characters using the keyboard. |
New values \u200b\u200bhave been added to HTML5 as shown in table. 2.
The browser support for these values \u200b\u200bis shown in Table 1. 3.
Value | Internet Explorer | Chrome | Opera | Safari | Firefox | Android | iOS |
color | 21.0+ | 11.01+ | |||||
date | 5.0+ | 10.62+ | 5.0+ | 5.0+ | |||
datetime | 5.0+ | 10.62+ | 5.0+ | 5.0+ | |||
datetime-local | 5.0+ | 10.62+ | 5.0+ | 5.0+ | |||
10.0 | 5.0+ | 10.62+ | 5.0+ | 4.0+ | 2.3+ | 3.1+ | |
month | 5.0+ | 10.62+ | 5.0+ | 5.0+ | |||
number | 10.0 | 6.0+ | 10.62+ | 5.0+ | 2.3+ | 4.0+ | |
range | 10.0 | 5.0+ | 10.62+ | 5.0+ | 23.0+ | 5.0+ | |
search | 10.0 | 5.0+ | 11.01+ | 5.0+ | 4.0+ | 4.0+ | |
tel | 10.0 | 5.0+ | 11.01+ | 5.0+ | 4.0+ | 3.1+ | |
time | 5.0+ | 10.62+ | 5.0+ | 5.0+ | |||
url | 10.0 | 5.0+ | 10.62+ | 5.0+ | 4.0+ | 2.3+ | 3.1+ |
week | 5.0+ | 10.62+ | 5.0+ | 5.0+ |
Default value
HTML5 IE Cr Op Sa Fx
HTML5 IE Cr Op Sa Fx
From the author: you should be aware of the type attribute on the input field. This attribute specifies the type of input in the form that the user will see. If the attribute is missing, or a new value is used in an old browser, the tag will still work. The default type will be set to type \u003d "text". This is the main point that allows you to use HTML5 forms today, even if you support older browsers. If you have new types such as email or search, then older browsers will display a simple text box.
Our registration form uses 4 of the 10 types that you all know: checkbox, text, password and submit. Below is the full list available in HTML5 input field types:
The HTML5 specification says about 9 more additional types, with which you can create specific UI elements, as well as perform native data validation:
There are four more date-related types included in HTML5.1 and the WHATWG HTML Living Standard, three of which are fairly well supported in modern browsers:
datetime (not supported in any browser)
Let's take a closer look at each new type, and also see how they can be used.
Search
Input type search (type \u003d "search") is a search field, a one-line input for entering one or more search phrases... From the specification:
"The difference between a text type and a search type is purely stylistic: on platforms where the search fields are different from regular text fields, the search type will match the input to the platform's styles."
Many browsers style search fields to resemble browser or operating system search boxes. Chrome, Safari, Opera and IE have added a function to delete text by clicking the "x" icon, which appears as soon as you start typing (see Figure 4.5). Chrome and Opera also clear date / time fields, and IE11 adds an "x" icon to almost all types, including text.
Figure 4.5. the search field is styled for operating system search fields
On Apple campaign devices, search boxes have rounded corners by default in Chrome, Safari, and Opera, which duplicates appearance search fields in the operating system... On tablets with dynamic keyboards, the Go button appears as a search icon or the word search. It all depends on the device. If you add a custom attribute, a magnifying glass icon appears in Chrome and Opera.
You can use type \u003d ”text” the old way, but the new search type is a visual clue to users where they need to click to find a site. In addition, the new type is very similar to the standard search fields that users are used to. There is no search on The HTML5 Herald, but it could be like this:
< form id = "search" method = "get" > < label for = "s" > Search< / label > < input type = "search" id = "s" name = "s" / > < input type = "submit" value = "Search" / > < / form > |
In browsers without support, the search type appears as a regular text field, so there is no reason not to use it where appropriate.
Email addresses
Not surprisingly, the email type (type \u003d "email") is used to set one or more email addresses. It supports the multiple Boolean attribute, which can be used to specify multiple addresses separated by commas (with spaces).
Let's change our form, put type \u003d "email" on the email fields:
< label for = "email" > My email address is< / label > < input type = "email" id = "email" name = "email" / > |
If you change the type from text to email, there won't be any visual changes. Input still looks like a regular text field. However, they are different.
The changes can be viewed on the touch device. When the email field receives focus, most touch devices (e.g. iPad or Android phone with Chromium) will display a keyboard optimized for entering an address email... The keyboard will display an @ symbol, a period, a space, but not a comma, as shown in Figure 4.6.
Figure 4.6. a field of type email with a custom keyboard on the device under iOS control
IN firefox browsers, Chrome, Opera and Internet Explorer 10 with incorrect input mail pops up an error message. This happens when you try to submit a form with text that is not recognized as one or more URLs. A typical error message is shown in Figure 4.7.
Figure 4.7. error message about incorrect email address entered in opera browser (left) and Firefox (right)
Note: custom validation messages
Don't like the default browser error message? Set yours with .setCustomValidity (errorMsg). SetCustomValidity takes only one parameter, the error message. If you have set your own validation message, then after correct entry, you must clear the line with the message (value false) for the form to be submitted:
function setErrorMessages (formControl) (var validityState_object \u003d formControl.validity; if (validityState_object.valueMissing) (formControl.setCustomValidity ("Please set an age (required)");) else if (validityState_object.rangeUnderflow) (formControl.setCustomValidity \\ "re too young");) else if (validityState_object.rangeOverflow) (formControl.setCustomValidity ("You \\" re too old ");) else if (validityState_object.stepMismatch) (formControl.setCustomValidity (" Counting half birthdays? " );) else (// if the input is valid, it must be false, or there will be an error formControl.setCustomValidity ("");))
function setErrorMessages (formControl) ( var validityState_object \u003d formControl. validity; if (validityState_object. valueMissing) ( formControl. setCustomValidity ( "Please set an age (required)") ; ) else if (validityState_object. rangeUnderflow) ( formControl. setCustomValidity ("You \\" re too young "); ) else if (validityState_object. rangeOverflow) ( formControl. setCustomValidity ("You \\" re too old "); ) else if (validityState_object. stepMismatch) ( Greetings to you, dear readers of the blog site. Today I want to talk about someone like HTML forms... Whatever the engine of your site (cms), it will definitely use forms created using Form and Input tags, as well as attributes and parameters Button, Checked, Value, Checkbox, Radio, Checkbox, Submit, in one form or another ... Well, you can also add elements to this to create drop-down lists and text fields - Select, Option, Textarea, Label, Fieldset, Legend. Why are we needed and how do forms work on modern websitesThe same site search string () is created using these tags, and then search on your project will be mandatory. Therefore, understanding how they are arranged and work will not hurt you at all for successful work on the design, and even with self-promotion and promotion it will not be superfluous. So, with the justification for the need to study these elements, I think there should be no more questions, so it's time to move directly to the study of their possible options. Yes, I also want to remind you that we have already reviewed a lot of materials on the topic of hypertext markup language, for example, three) and. At their core, forms consist of elements, for the creation of which, inside the main container from Form tags, various tags are inserted - Checked, Value, Checkbox, Radio, Checkbox, Submit, etc. We just need to place its code in any convenient place of the site template by specifying with tags and their attributes how it should look. This can be a text box with a submit button for the query you entered, choices with radio buttons (where you can leave only one of the provided buttons pressed), multiple text boxes with a submit button (), and more. For example, in the case of "search", using the Value attribute, you can specify what exactly will be written on the button located next to the field for entering a query. The data entered in the forms must be further processed in some way. For example, in the case feedback the user, after filling in the field with his name, enters his E-mail and the text of the message, and then clicks on the send button, will have the right to hope to send data from the form to the E-mail of the author of the site. But unfortunately, it is not possible to implement this using only one hypertext markup language (). For these purposes, you will need special program a handler that, after the user clicks the submit button, will take all the data from the feedback fields and send it to the resource owner by E-mail. Which program will do this, you must specify yourself using the Action attribute. Usually a processing program is a script written in PHP. Therefore, in the Action attribute of the Form tag, you will need to specify the path to the file of this script, which is located on your hosting server. I will give as an example the subscription to the RSS feed of my blog via E-mail: A little incomprehensible, probably, it seems at the beginning, but I think that everything will become clear as the story progresses. Form and Input tags for creating buttons, checkboxes and radio buttonsAny form must be enclosed in opening and closing tags Form... This is a kind of container for their creation. This tag has a number of required and optional attributes:
Consider the rest of the tags that allow you to create a variety of web forms. The most versatile is Input... Inside it, the Type attribute must be prescribed, which determines what exactly the HTML form created with this tag will be. The following elements can be created using Input and Type:
Input has no end tag. What exactly the web form created with it will look like depends entirely on the parameter specified in the Type attribute. If Type is not specified, then a text field will be created by default. Examples of forms created on Input with different values \u200b\u200bfor TypeOther attributes of the Input tag and examples of their useLet's see what the rest of the attributes are for:
Now let's go over everything examples of forms with Input... The appearance of the text field is similar to the appearance of the password input field, so we will only consider the option of creating Text, for example, to enter an email address: Note that this form uses the Input tag twice — once to create each of the two radio buttons. Moreover, each of them contains the Name attribute with the same value (rezultat), and the Value value is different (YES and NO). This means that when processing it, if any of the radio buttons is selected, a variable will be sent whose name is written in Name, but the value of this variable will depend on which radio button was selected. Let's consider an example of creating a web form with checkboxes: Checkboxes differ from radio buttons by the ability to select several options at once. Name serves to define in the handler file in which checkbox the checkboxes are set, and Value - sets the value that will be sent to the handler (if Value is not specified, then the text located next to this checkbox will be sent to the handler). Select, Option, Textarea, Label, Fieldset, Legend - drop-down lists, text areas and other elements of web formsTo begin with, I would like to remind you a little what, in fact, web forms are and why they are needed on the site pages. They are primarily designed to repeat the elements available in any operating system in a user-friendly way: buttons, text input fields, drop-down lists, checkboxes, radio buttons, and the like. All users, without any additional explanation, understand the purpose of these elements and if they see the Html button of the form, they understand that they need to click on it. Moreover, all its constituent elements (like Select, Option, Textarea, Label, Fieldset, Legend) are already finished blanks (containers), to insert which it will be enough just to use the required tag with the necessary attributes and parameters. Browsers themselves know how to display a particular element of a web form. True, the options for displaying the same element of it in different browsers may slightly differ from each other, but, as a rule, not significantly. So it turns out that web forms in Html are an attempt to transfer key elements used in any operating system, to the pages of the website. But why might they be needed on site pages? In principle, for the same purpose for which similar elements are used in operating systems - the transfer of data from the user. In the case of forms, data from the user is transmitted to the server, where it is processed by a special program (unfortunately, the hypertext markup language does not allow data processing). Although, the data can be sent not only to the server, but also, for example, by e-mail to the address specified in the Action attribute of the Form tag. When sending data from Html to E-mail, the user who fills in the fields, after pressing the button for sending data, will launch the mail program used on his computer by default. The opening Form tag in this case should look something like this:
The following attributes can be used with Textarea:
Label - what is this Html tag in the form for?The Html Label tag allows you to implement one very interesting feature in forms that is available in operating systems. There, if you remember, in order to activate any element, it is not necessary to click on it, you can click on the name of this element - it will still be activated. This does not happen in web forms by default - you need to click on the very element of the Html form to activate it. For example, you need to click on a checkbox in order to put a checkmark in it. Clicking on the text next to the flag will have no effect. Try it yourself: As you can see, clicking on the text to activate this element is useless - you need to click on it yourself. This is exactly what the Label tag is intended to fix. It allows you to make the text next to the web form element clickable, which is undoubtedly will improve usability. But how to link the Html element of the form and the text? To do this, add an ID with a unique parameter to the attribute, and surround the text with the opening and closing Label tags. And that is not all. In the opening Label tag, you need to register the For attribute, the parameter of which must be exactly the same as the ID attribute in the Html tag of the form element. It turns out something like this: As you can see, now, thanks to the use of Label, web form elements can be activated not only by clicking on it, but also by clicking on the text located next to it. Fieldset and Legend - breaking the shape into piecesYou've probably often seen that large forms in Html are divided into groups (Fieldset), which are surrounded by a frame, and each such group has its own title (Legend). This is done with just two tags: Fieldset and Legend. They are paired, i.e. they must have an opening and closing. So, to create a group of component parts, you need to wrap all these parts in the opening and closing tags of the Fieldset. And in order to set a title (Legend) for this group, you need to immediately after the opening Fieldset write a construction from the opening and closing Legend, between which you need to insert the text of the group title. Here's an example of creating groups using Fieldset and Legend: Good luck to you! See you soon on the pages of the blog site you can watch more videos by going to");"> ![]() You might be interested Select, Option, Textarea, Label, Fieldset, Legend - Html tags of the drop-down list and text box form Tag (from the English. input - input) is one of the versatile form elements and allows you to create different parts of the interface and provide user interaction. Mainly designed to create text fields, various buttons, radio buttons and checkboxes. Main attribute that defines the type of the element - type. It allows you to set the following form elements: a text field (text), a password field (password), a radio button, a checkbox, a hidden field, a button, a button to submit a form (submit), a button to clear the form (reset), a field for sending a file (file), a button with an image (image), etc. Each element has its own list of attributes that determine its appearance and characteristics. In addition, more than a dozen new attributes have been added to HTML5. SyntaxNo closing tag required. WAI ARIAThere is no default role. Valid values \u200b\u200bfor role:
Attributes
acceptSets the filter for the types of files that you can submit via the file upload field. The file type is specified as a MIME type, with multiple values \u200b\u200bthey are listed separated by commas. If a file does not match the set filter, it is not shown in the file selection window. Applies to the file upload field ( ). Browser support Default value altThe alt attribute sets alternative text for the image field. This text allows you to get text information about the picture when the loading of images is disabled in the browser, and is also intended for search engines. Syntax
The values Any suitable text string. Default value autocompleteThis attribute helps to fill in the form fields with the text that was entered in them earlier. The values \u200b\u200bare stored and substituted by the browser, while autocomplete, for security reasons, can be disabled by the user in the browser settings and cannot be controlled by the autocomplete attribute in this case. When you enter the first letters of the text, a list of previously saved values \u200b\u200bis displayed, from which you can select the desired one. Autocompletion of a specific form field is bound to its name attribute and is lost when the value is changed. Syntax
The values
Default value Depends on browser settings. autofocusAutomatically sets focus to the form field. In such a field, you can immediately type text without explicitly clicking on it with the mouse cursor. Syntax
The values Default value By default, the autofocus attribute is not set. checkedThis attribute determines whether a form element such as a checkbox or radio button is pre-marked. In the case of using radiobutton, only one element of the group can be checked; for checkboxes, at least all elements can be checked. Syntax
The values Default value dirnameIf the dirname attribute is present, a name / value pair is sent to the server, where the name is specified by the dirname attribute, and the value is substituted by the browser. For left-to-right text, the value will be ltr, and for right-to-left text (Hebrew, for example) the value will be rtl. Syntax
The values An arbitrary text string that serves as the name of the parameter. Usually, dir is added at the end of the line to indicate that this parameter specifies the direction of the text. Default value disabledBlocks access and modification of the form field. In this case, it is displayed gray and unavailable for activation by the user. In addition, such a field cannot receive focus by pressing the Tab key, with the mouse, or in any other way. However, this state of the field can be changed using scripts. The value locked in the field is not transmitted to the server. Syntax
The values Default value This attribute is disabled by default. formAssociates a field with a form by its identifier. Such a connection is necessary in the case when the field is located outside The values Form identifier (value of element id attribute |