Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean when the form action attribute is "#" (number/pound symbol/sign/character)?

Tags:

html

forms

What does it mean when the form action attribute is "#" (number/pound symbol/sign/character)?

What happens when a form input's formaction attribute is set to "#"? Does this prevent the input from being submitted to the server?

<form method="GET" action="example.php">
    <input type="text" size="20" name="text1" value="text1" formaction="#"/>
    <input type="text" size="20" name="text2" value="text2"/>
    <input type="submit" value="Submit"/>
</form>
like image 395
XP1 Avatar asked Jan 14 '12 11:01

XP1


People also ask

What should I put in a form action attribute?

The HTML form action attribute defines what should happen to data when a form is submitted on a web page. The value of the action attribute should be the URL of the web resource that will process the contents of the form.

What HTML element form attribute action is for?

The HTML | action Attribute is used to specify where the formdata is to be sent to the server after submission of the form. It can be used in the <form> element. Attribute Values: URL: It is used to specify the URL of the document where the data to be sent after the submission of the form.

What is form attribute?

The form attribute specifies the form the element belongs to. The value of this attribute must be equal to the id attribute of a <form> element in the same document.

What does form action mean in php?

Form ACTION attribute with PHP. In php when we submit the form the form where should be sent it depend on Action attribute. The Action attribute is used to give link to another form. We can send the form data to another PHP script page, or the same PHP page or any other form or script.


1 Answers

The meaning of # as a URL reference (whether as action or formaction attribute value or otherwise) is a reference to the start of the current base document. The base document is the current document, unless a <base href=...> tag has been set.

What happens depends on the situation. Typically, the browser requests for the page again with a query part in the URL (and the page is loaded again, which may imply that client-side scripts are run), but if the same query had been used earlier, the browser probably uses its cache. Moreover, as the start of the document is referred to, focus on any form element is lost and the page may scroll backwards.

So although # is fairly common in some coding styles, it is not reliable; its purpose is better achieved using client-side event handlers.

The formaction attribute has a meaning only for submit buttons. A text input element does not constitute a submit button, even though it may trigger form submission, so here the attribute is ignored.

like image 77
Jukka K. Korpela Avatar answered Sep 17 '22 15:09

Jukka K. Korpela