Events in html php css dropdown. We create stylish drop-down lists. Plain HTML, CSS dropdown

Greetings, dear readers of the blog site. Today I want to talk about things like HTML forms. Whatever the engine of your site (cms), it will definitely use forms created using the Form and Input tags, as well as the Button, Checked, Value, Checkbox, Radio, Checkbox, Submit attributes and parameters .

Well, you can also add elements to this for creating drop-down lists and text fields - Select, Option, Textarea, Label, Fieldset, Legend.

Why forms are needed and how they work on modern sites

The same site search string () is created using these tags, and searching for that on your project will be mandatory. Therefore, understanding how they are arranged and work will not hinder you at all for successful work on the design, and it will not be superfluous for self-promotion and promotion.

So, with the rationale for the need to study these elements, I think there should be no more questions, so it's time to proceed directly to the study of their possible options.

Yes, I also want to remind you that we have already managed to consider a lot of materials on the topic of hypertext markup language, for example, three ) and .

At their core, forms consist of elements, to create which various tags are inserted inside the main container from Form tags - Checked, Value, Checkbox, Radio, Checkbox, Submit, etc. We just need to place its code in any place convenient for this site template , specifying how it should look with the help of tags and their attributes.

This could be a text box with a submit button for the entered request, radio button choices (where you can only leave 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 of feedback, the user, after filling in the field with his name, entering his E-mail and message text, and then clicking on the submit button, will have the right to hope to send the data from the form to the E-mail of the site author. But to implement this using only one hypertext markup language (), unfortunately, is not possible.

For these purposes, a special handler program is required, which, after the user clicks on the send button, will take all the data from the feedback fields and send them to the E-mail owner of the resource. Which program will do this, you must specify yourself using the Action attribute.

Typically, the 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 located on the server of your hosting. I will give as an example a subscription to the RSS feed of my blog via E-mail:

A little unclear, probably, it seems at first, but I think that everything will become clearer as the story goes on.

Form and Input tags for creating buttons, checkboxes and radio buttons

Any 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:

  1. Name - a unique name that must be specified if several web forms will be used in the Html file where you are doing something
  2. Action - a mandatory attribute indicating the path to the script to which the data from it will be transferred for further processing
  3. Method - using it you can change the method of passing data from this web form to the handler file script. If you do not specify it, then the Get method will be used by default, which, in fact, is intended mainly for variables and short messages, and also passing data in an open way through the browser's address bar. To pass form data to the handler script, it is still better to use POST method, designed specifically for transferring text messages in a closed way

Let's look at 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 written, which determines what exactly the HTML form created using this tag will be like.

With Input and Type , you can create the following elements:

  1. single line text fields (Type="Text")
  2. password fields (Type="Password")
  3. checkboxes (Type="Checkbox")
  4. radio buttons (Type="Radio")
  5. hidden fields (Type="Hidden")
  6. normal buttons (Type="Button")
  7. buttons for submitting data to the handler (Type="Submit")
  8. buttons to bring the web form to its original state (Type="Reset")
  9. fields for uploading files to the server (Type="File)
  10. image buttons (Type="Image")

Input does not have a closing tag. What exactly will be the web form created with it depends entirely on the parameter specified in the Type attribute. If Type is not specified, a text field will be created by default.

Examples of forms created on Input with different values ​​for Type

Other attributes of the Input tag and examples of their use

Consider what the rest of the attributes are for:

  1. Name - if the data is to be sent to the handler program script, then you must specify a parameter for the Name attribute. Under this name, the data submitted from the form will appear in the information handler program.
  2. Size - with the help of it the size of the field of the created web form is set. The value is specified in the number of characters that can fit in this field. If Size is not specified, the width will default to 24 characters.
  3. Maxlength - by default, the number of characters that can be entered in the Html form is not limited, but using Maxlength you can set this limit. More characters than it will be indicated, you will not be able to enter in the field
  4. Value - with it you can set what exactly will be written by default in the field or on the send data button
  5. Checked is a flag attribute that can be inserted into the Input for radio buttons (radio) or for checkboxes (checkbox). In this case, this radio button or checkbox will be active when the page with the webform is loaded (they will already have a checkmark)

Now let's look at everything form examples with Input. The appearance of the text field is similar to the appearance of the password field, so we will only consider the option of creating Text, for example, to enter an email address:

Now let's look at creating a web form with radio buttons (Radio):

Note that this form uses the Input tag twice, once to create each of the two radio buttons. Moreover, each of them has the Name attribute with the same value (resultat), 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, the name of which is written in Name, but the value of this variable will depend on which radio button was selected.

Consider the example of creating a web form with checkboxes (Checkbox):

Checkboxes differ from radio buttons by the ability to select multiple options at once. Name is used to determine in the handler file which checkbox the checkboxes are set in, and Value specifies the value that will be sent to the handler (if Value is not set, 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 web form elements

To begin with, I want to remind you a little what, in fact, web forms are and why they are needed on the pages of the site. They are primarily designed to repeat the elements available in any operating system in a user-friendly form: buttons, text entry fields, drop-down lists, checkboxes, switches, and the like.

All users, without any additional explanation, understand the purpose of these elements, and if they see an Html form button, 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), for inserting which it will be enough just to use the desired tag with the necessary attributes and parameters.

Browsers themselves know how to display a particular web form element. True, the display options for the same element in different browsers may differ slightly from each other, but, as a rule, not significantly.

That. it turns out that web forms in Html are an attempt to transfer key elements used in any operating system, to website pages. But why might they be needed on the pages of the site?

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 transferred to the server, where it is processed by a special program (hypertext markup language, unfortunately, does not allow data processing).

Although, 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 clicking on the send data button, will launch the mail program used on his computer by default.

The opening Form tag should then look something like this:

Select and Option are dropdown tags

All webform elements that create fields with drop-down lists are formed in the same way. First, the combo box container is defined using the opening and closing Html Select tags. And then, inside this container, separate containers are created with items (elements) of this list. This is done with opening and closing Option tags.

It turns out something like this:

But this is a simplified design, because Select and Option have a number of attributes, which define the properties and appearance of the generated combo box.

  1. Name - You must provide a unique name for this web form element created using Select. This name will be passed to the server in the data handler program as a name for the variable. The value of the Value attribute (set in Option for each item) of the drop-down list item that the user selects will be passed as the value of this variable.
  2. Size - with it you can set the number of displayed items. In other words, using Size, you can set the height of the list, measured in the number of lines displayed. If you do not explicitly specify the Size value in the Select tag, then the default height of the drop-down list will be used, and it will be different if the Multiple attribute is absent or present in the Select:
    1. If Multiple is present in Select, then the height of the drop-down list in the web form will by default be equal to the number of its elements. Those. all the items in the multi-select dropdown list will be shown. See the plural example below. If the Size attribute in Select is set to less than the number of items, then a scroll bar will appear on the right.
    2. If there is no Multiple in Select, then the height of the drop-down list in the web form will default to one line. Those. only one line will be visible, and the remaining items will be available only by pressing the elevator button (on the right). See example below
  3. Multiple - attributing this attribute in the Select tag will allow you to create a drop-down list with the ability to select multiple items at the same time. Read more about this attribute below.

Forms with drop-down lists can be divided into two options. In the first option, you can select only one element (line) of the field with a drop-down list, in the second option, by holding Ctrl or Shift, you can select several of the available items at the same time.

In this case, in the second option, data on all selected points will be sent to the server. Which drop-down list will be created is determined by the presence or absence of the Multiple attribute in the Select tag.

Multiple is specified in Select without a parameter, because it is written simply Multiple and that's it. If it is present, then a drop-down list webform with multiple selection (by holding Ctrl or Shift) will be created.

A variant of the field with a drop-down list, in which there will be multiple choice possible, will look something like this:

On the right is an example of a multi-select dropdown web form based on the code above. As you can see, holding Ctrl or Shift can select multiple items at the same time.

If there is no Multiple attribute in the Select tag, then only one element of this drop-down list (row) can be selected.

An example where only one item can be selected can be seen here:

Label Select SelectED Website Legend

Option tag attributes


In the created drop-down list (using Select and Option), you can add something like separators with the group heading, which will differ from the rest of the menu items in font style.

To create a group from the drop-down list items, you need to enclose them in the opening and closing tags of the Optgroup form, and in the opening Optgroup tag, specify the Label attribute, as a parameter of which you will need to enter the desired group name.

For example like this:

Label Select
SelectED Website Legend

Textarea - creating a text field in a form

There is one more web form element that we have not considered - Textarea (a field with the ability to enter multiline text). It is created using a paired Html Textarea tag. Moreover, it is possible to transfer text to a new line in it and it will be transmitted to the server, taking into account the transfers made.

So, to create a multi-line text field, you need to write an opening and closing Textarea, and between them you can add text that will be visible when the page with the web form is loaded. The user can then erase this text and write his own.

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 that the Label tag is designed to fix. It allows you to make the text next to the web form element clickable, which is undoubtedly improve usability.

But how to link form Html element and text? To do this, you need to add an ID with a unique parameter to the attribute, and the text must be surrounded by opening and closing Label tags. And that is not all. In the opening Label tag, you need to write 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 - splitting the form into parts

You probably often saw that large forms in Html are divided into groups (Fieldset), which are circled in a frame, and each such group has its own header (Legend). This is implemented using just two tags: Fieldset and Legend. They are paired, i.e. they must have an opening and a closing one.

So, to create a group of component parts, you need to enclose all these parts in the 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 construction from the opening and closing Legend, between which you need to insert the text of the group's title.

Here is an example of creating groups using Fieldset and Legend:



Good luck to you! See you soon on the blog pages site

You may be interested

Select, Option, Textarea, Label, Fieldset, Legend - Html tags of dropdown list form and text field
Lists in Html code - UL, OL, LI and DL tags
MailTo - what is it and how to create an email link in Html
How colors are set in Html and CSS code, selection of RGB shades in tables, Yandex results and other programs
What is Html Hypertext Markup Language and how to list all tags in W3C validator
How to insert a link and a 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 - deprecated text formatting in pure HTML (without using CSS)
How to create a hyperlink (A, Href, Target blank), how to open it in a new window on the site, and also make an image a link in Html code

Over the past two years, the development of web applications (sites) has moved far ahead and what we used to create a site earlier is already outdated or more recent methods have appeared.

Previously, to create a dropdown list in html ( in English. — dropdown), we just used

In this example, we tag

In the browser it looks like this:

Grouping menu items

Let's consider the following tag A that is used to group related data in a dropdown list name="black&white"> label="whitelist">

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 disabled boolean attribute, we will disable one group (" Group B"):

</span> An example of using the disabled attribute of an HTML tag <optgroup><span>

The result of our example:

Disabling the list and multi-selection

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

In this example, we have created two dropdown lists. For the first list, we used the disabled attribute, which prevents the list from being interacted with (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 (via ctrl on Windows and through command on Mac).

In the browser it looks like this:

Text area

The result of our example:

Disabling the text area

By analogy with the previously considered elements, the tag



type = "submit" name = "submitInfo" value = "submit" > !}

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