Creating a form in HTML. How to create a drop-down list in html? Form with drop-down list in css examples

HTML tags, defining HTML forms on the site

We create websites and individual pages on the Internet to communicate with visitors.

HTML forms are used to register visitors on the site, for interactive surveys and voting, allow you to send messages, make purchases, and so on. HTML The form is created for one purpose: collecting and subsequently transmitting information for processing by a software script or via email.

Example HTML form | Enter the site

Tags, attributes and values

  • - determine the shape.
  • name="" - defines the name of the form.
  • method="" - defines the method of sending data from the form. Values: "get" (default) and "post" . The "post" method is often used, as it allows large amounts of data to be transferred.
  • action="" - defines the url at which the data is sent for processing. In our case - enter_data.php ..
  • - define such form elements as buttons, switches, text fields for data entry.
  • type="text" - defines a text field for data entry.
  • type="password" - defines a field for entering a password, with the text displayed in the form of asterisks or circles.
  • type="checkbox" - defines a radio button.
  • type="hidden" - defines a hidden form element - used to transmit additional information to the server.
  • size="25" - length of the text field in characters.
  • maxlength="30" - the maximum allowed number of entered characters.
  • value="" - defines the value that will be sent for processing if it applies to radio buttons or switches. The value of this attribute as part of a text field or button will be shown as, for example, Vasya or Login in the example above.

Example HTML form | Comments on the site

Example HTML form




Name



Mail










Tags, attributes and values

  • action="http://site/comments.php" - defines the url to which data from the form will be sent.
  • id="" - defines the name and identifier of the form element.
  • name="" - defines the name of the form element.
  • - define a text field as part of the form.
  • cols="" - determines the number of columns of the form text field.
  • rows="" - defines the number of rows of the form text field.

If between place text, it will be shown inside the field as an example that can be easily removed.

Example HTML form | Drop-down list

HTML forms




Tags, attributes and values

  • - define a list with positions to select.
  • size="" - determines the number of visible list positions. If the value is 1 , we are dealing with a dropdown list.
  • - determine the positions (items) of the list.
  • value="" - contains the value that will be sent by the form to the specified url for processing.
  • selected="selected" - highlights a list item as an example.

Example HTML form | List with scroll bar

By increasing the value of the size="" attribute, we get a list with a scroll bar:

First position Second position Third position Fourth position

HTML forms




For this option, use the multiple="multiple" flag, which makes it possible to select multiple positions. Its absence allows you to select only one item.

  • type="submit" - defines a button.
  • type="reset" - defines a reset button.
  • value="" - defines the label on the button.
  • See additionally:

    Designed to create a list of suggested items from which the user can select one or more. .

    Limited to tags ... focus when loading the page. The value can be set in three ways: disabled Disables selection from the list. The value can be set in three ways:

    multiple Allows you to select multiple list items at the same time. Please note that with multiple selection, there may be several variables with the same name in the data stream from one form.

    Your processing program should anticipate such situations and handle them correctly. name Name of the list. Required attribute.

    Limited to tags
    disabled Disables selection of a list item.

    And here's how the PHP script is used to get the HTML select option value:

    ". $_POST["selfphp"].""; } ?>

    If the form specifies the GET method then use PHP array $_GET[“”].

    Styling a Dropdown List with CSS

    Now let's look at how to define dropdown list styles



    Inside the select element are option elements - list elements. Each option element contains a value attribute, which stores the value of the element. However, the value of the option element does not have to match the text it displays. For example:

    With the selected attribute we can set the default selected element - it doesn't have to be the first element in the list:

    Another attribute, disabled, can be used to prevent a specific element from being selected. Typically, elements with this attribute are used to create headings:

    To create a multiple choice list, you need to add the multiple attribute to the select element:

    Select element in HTML5




    By holding down the Ctrl key, we can select several elements in such a list:

    Select also allows you to group elements using a tag :

    Select element in HTML5



    Using element groups applies to both drop-down and multiple-select lists.



    
    Top