What does the action attribute of the html form tag mean? What are the uses? (with examples)

寻∝梦
Release: 2018-08-29 14:50:44
Original
15699 people have browsed it

This article mainly introduces the usage of the action attribute of the HTML form form tag. The usage introduction and examples are all in it. Now let us take a look at it.

First of all, let’s introduce it first Regarding the meaning of the action attribute of the HTML form tag:

The action attribute of the form tag is a necessary attribute in a form. The action attribute specifies where to send the form data when the form is submitted.

Let’s look at the first example of the action attribute of the form tag:

The form below has two input fields and a submit button. When the form is submitted, The form data will be submitted to the page named "form_action.asp":

<form action="form_action.asp" method="get">
  <p>输入用户名: <input type="text" name="fname" /></p>
  <p>再输用户名: <input type="text" name="lname" /></p>
  <input type="submit" value="提交" />
</form>
Copy after login

The rendering of this is below:

What does the action attribute of the html form tag mean? What are the uses? (with examples)

The effect is obvious, basically every form requires the action attribute.

Now let’s talk about the usage of the action attribute of the form tag:

The value of the action attribute in the form form is the URL that the form is submitted to. If we do not set the action attribute , then the default form is still submitted to the current page. The following is an introduction to the three usages of the action attribute:

  • action="" and action="#", without the action attribute, have the same effect. , are submitted to the current page (that is, document.location.href)

  • ##action="currentPage.xxx" If currentPage.xxx represents the current page, then it is submitted to the current page, colleagues Jumping to the current page, of course, you will not see the change in the url; if currentPage.xxx is a non-current page, it will be submitted to the non-current page and also jump to the non-current page

  • form The difference between action="" and action="currentPage.xxx" when submitting to itself:

Usually to save trouble, we usually set the action attribute of the form to action=""/action ="#" or simply don't write it, but this will cause a problem, that is, when the action is set to action="", the page actually submitted when the form is submitted is action="currentPage.xxx?arguments=values&….", That is to say, if the current page has parameters, the parameters will also be submitted, and the priority of the parameters will be higher than the parameters submitted by the
control, that is, if action="currentPage.xxx?arguments=values&…." When arguments has the same name as the
element, when obtaining the value, the action="currentPage.xxx?arguments=values&…." value will overwrite the value of
and obtain an incorrect value from the page.

Example: SpecTop.asp page is the page where the form is to be submitted, and there are parameters passed from the upper-level page

action=""The page when actually submitted: SpecTop.asp?ClassID=000100200005&SpeID=947&SpeType =3

If there is in
, the value obtained when submitting will be 947, not 1000 , and action="currentPage.xxx" can get 1000

Well, the above is the complete introduction to the action attribute of the HTML form tag. If you have any questions, you can leave a message below.

【Editor's Recommendation】

How to wrap the text in the pre tag in html? Usage examples of html pre tag

What does the HTML ul tag mean? Detailed explanation of the role of HTML ul tag

The above is the detailed content of What does the action attribute of the html form tag mean? What are the uses? (with examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template