Html form submit button with dropdown list. HTML form elements - a drop-down list (select, option, optgroup tags), a textarea, and applying a label, fieldset and legend. Optgroup tag attributes

The simplest dropdown list in HTML is easy to create using the select tag. This is a container tag, option tags are nested in it - they define the list items.

There are several options for lists that can be made using the select tag: a drop-down list (options drop out after clicking on the main field or hovering over it) and a multiple choice list - in it the user can select several items. The former are more common; they are an important navigation element in modern websites. The multiple choice drop-down list can be used, for example, in catalogs where you need to select several product characteristics.

You can change the appearance and properties of lists using generic and custom attributes.

Select tag attributes

1. Multiple - sets multiple choice.

2. Size - sets the number of visible lines in the list, that is, the height. And here it all depends on whether the multiple attribute is present or not. If yes, and you do not specify size, then in the presence of multiple, the user will see all possible choices, if multiple is absent, then only one line will be shown, and the rest of the visitor will be able to read when he clicks on the elevator icon on the right side. If size is specified and it is less than the number of options, then a scroll bar will appear on the right.

3. Name - name. The drop-down list can be dispensed with, but it may be necessary to interact with the handler on the server. As a rule, the name is still indicated.

The select tag does not have the required attributes, unlike the option tag.

Option nested tag attributes

  1. Selected - designed to select a list item. The user will be able to select more than one item if the multiple attribute is set (see above).
  2. Value - value. This attribute is required. The web server must understand exactly which list items the user has selected.
  3. Label. With this attribute, you can shorten list items that are too long. For example, “Milan” will be displayed instead of the option “Milan is the administrative center of Lombardy” specified in the tag. Northern Italy". This attribute is also used to group items in a list.

As for the width of the list, it is set by default to the length of the widest text in the list. Of course, the width can be changed using HTML styles.

Dropdown in other ways

It can be done using CSS, for example, a list will appear when you hover over a page element. JavaScript provides excellent options for creating lists, which is simplified by the Jquery library. The dropdown list connected with this library can be very complex, for example, cascading. That is, when you select an item in one list, the following list appears, for example, there is a menu item "Women's clothing" (when you hover, then when you select one of the types, for example, "Outerwear", a list with the elements: jackets, parkas, coats, short coat, fur coats, etc.

We've roughly listed the main ways in which you can create a dropdown list. Of course, there are a lot of nuances in and in JavaScript that allow you to change the functionality and appearance of lists.

In this article, we will look at the elements that allow you to create drop-down lists, learn how to form groups in these lists, consider how to disable items and even groups of lists, get acquainted with the element that allows you to create a multi-line text field, you can use it later inside HTML forms (element

).

Drop-down list

The first item in the list is usually displayed as selected, but you can add the selected attribute to that item to set a predefined option.

let's

</span>Example of using an element <select><span>

In this example we tagged

In the browser it looks like this:

Grouping menu items

Let's take a look at the next tag which is used to group related data in a dropdown name \u003d "black & white"\u003e label \u003d "Whitelist"\u003e

In this example, we have selected 2 groups with the tag ... The element's label attribute specifies the name of the selected group in bold:

In the following example, using the boolean disabled attribute, we will disable one group (" Group B"):

</span>Example of using the disabled attribute of the HTML tag <optgroup><span>

The result of our example:

List mute and multi-select

</span>The disabled and multiple tag attributes <select><span>

In this example, we have created two dropdown lists. For the first list, we used the disabled attribute, which does not allow us to interact with the list (disables it).

For the second list, we used the multiple attribute, which indicates that it is allowed to select several options in the list at once (through Ctrl in Windows and through Command on Mac).

In the browser it looks like this:

Text area

The result of our example:

Disabling the text area

Similar to the previously discussed elements, the tag


type \u003d "submit" name \u003d "submitInfo" value \u003d "(! LANG: submit" > !}

In this example, we have created two text areas (element

As you can see, clicking on the text to activate this element is useless - you need to click on it yourself. This is exactly the state of affairs and is intended to fix the tag Label. 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 pieces

You'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 opening and closing Fieldset tags. And in order to set a title (Legend) for this group, you need to immediately after the opening Fieldset write a structure 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 might be interested

Select, Option, Textarea, Label, Fieldset, Legend - Html tags of the dropdown and textbox form
Lists in Html code - tags UL, OL, LI and DL
MailTo - what is it and how to create a link in Html for sending an Email
How colors are set in Html and CSS code, selection of RGB shades in tables, Yandex issue and other programs
What is hypertext markup language Html and how to view a list of all tags in the W3C validator
How to insert link and picture (photo) into HTML - IMG and A tags
Tables in Html - Table, Tr and Td tags, as well as Colspan, Cellpadding, Cellspacing and Rowspan to create them
Font (Face, Size and Color), Blockquote, and Pre tags - legacy plain HTML text formatting (no CSS)
How to create a hyperlink (A, Href, Target blank), how to open it in a new window on the site, as well as make a picture a link in the Html code