Detailed explanation of HTML form elements (Part 1)

Detailed explanation of HTML form elements (Part 1)

HTML forms are used to collect different types of user input.

HTML forms are used to collect user input;

The form element defines an HTML form.

<form>
    form elements
</form>

Action Attributes

The action attribute defines the action to be performed when the form is submitted.

The common way to submit a form to the server is to use a submit button.

Typically, the form is submitted to a web page on a web server.

If the action attribute is omitted, the action will be set to the current page.

Method property

The method attribute specifies the HTTP method (GET or POST) to use when submitting the form:

When to use GET?

You can use GET (the default method):

If the form submission is passive (such as a search engine query) and contains no sensitive information.
When you use GET, the form data is visible in the page address bar: action.jsp?name=xxxx&sex=female
*ps: GET is best suited for submitting small amounts of data. Your browser will set a capacity limit.

When to use POST?

You should use POST:

If the form is updating data, or contains sensitive information such as passwords.
POST is more secure because the data being submitted is not visible in the page address bar.

HTML forms contain form elements

Form elements refer to different types of input elements, checkboxes, radio buttons, submit buttons, text fields, etc.

The <input> element

The <input> element is the most important form element.

The <input> element has many forms, depending on the type attribute.

-Text input: type="text"

<form>
<label>Username</label>
<input type="text" name="">
</form>

-Submit button: type="submit" (defines the button that submits form data to the form handler)

<form action="action.jsp">
<input type="submit" value="Submit">
</form>
/*Coordinate with action*/
/*If the value attribute of the submit button is omitted, the button will get the default text, which is the two words "Submit"*/

- Single choice: type="radio"

<form>
<label>Gender</label>
<input type="radio" name="sex" value="male" checked>Male
<br>
<input type="radio" name="sex" value="female">Female
</form> 
/*When the values ​​in name are consistent, the single selection effect can be achieved*/
/*checked means the selected state, you can also write checked="checked"*/

-Checkbox: type="checkbox"

<form>
<label>Hobbies</label>
<input type="checkbox" name="vehicle" value="Sports"><label>Sports</label>
<br>
<input type="checkbox" name="vehicle" value="Beauty"> <label>Beauty</label>
</form>

/*checked means the selected state, you can also write checked="checked"*/

-Define button: type="button"

<form>
<input type="button" onclick="alert('Welcome to 123WORDPRESS.COM!')" value="Click me!">
</form> 

/*Also a normal button*/

- Drop-down list: <select> element

<form>
<select name="cars">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="fiat">Fiat</option>
    <option value="audi">Audi</option>
</select>
</form> 

The <option> element defines an option to be selected.
Lists usually display the first option as the selected option.
You can define predefined options by adding the selected attribute.

-Textarea: <textarea> element (defines a multi-line input field)

<form>
<textarea name="message" rows="10" cols="30">
Enter the content here!
</textarea>

-Button: <button> element

<form>
<button type="button" onclick="alert('Welcome to 123WORDPRESS.COM!')">Click!</button>

To learn more about the properties of form elements, please click on the link: https://www.jb51.net/web/571879.html

The above is the full content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support of 123WORDPRESS.COM!

<<:  Solution to the problem of insufficient storage resource pool of Docker server

>>:  About Generics of C++ TpeScript Series

Recommend

Solution to the error when installing Docker on CentOS version

1. Version Information # cat /etc/system-release ...

Implementation script for scheduled database backup in Linux

Table of contents Scenario: The server database n...

How to install mysql via yum on centos7

1. Check whether MySQL is installed yum list inst...

Overview of the Differences between Linux TTY/PTS

When we type a letter on the keyboard, how is it ...

Deep understanding of the mechanism of CSS background-blend-mode

This article is welcome to be shared and aggregat...

Two solutions for Vue package upload server refresh 404 problem

1: nginx server solution, modify the .conf config...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

CentOS6.9+Mysql5.7.18 source code installation detailed tutorial

CentOS6.9+Mysql5.7.18 source code installation, t...

The submit event of the form does not respond

1. Problem description <br />When JS is use...

Solution to the problem that the image name is none after Docker load

Recently, I found that after using the docker loa...

Example of MySQL slow query

Introduction By enabling the slow query log, MySQ...

CSS3 achieves infinite scrolling/carousel effect of list

Effect Preview Ideas Scroll the current list to t...

A detailed introduction to setting up Jenkins on Tencent Cloud Server

Table of contents 1. Connect to Tencent Cloud Ser...

Deploy Confluence with Docker

1. Environmental requirements 1. Docker 17 and ab...