form action="#"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Please explain.  I've always seen action defined as a url.  What is '#?

Re: form action="#"

okey wrote:
Quoted text here. Click to load it

The URL of the page being viewed.

You might use it if you have a script that displays a form and processes
the data entered into the form, so that the form sends data to the same
URL that created it.

Re: form action="#"

Scott Bryce wrote:
Quoted text here. Click to load it

No it's not. It'a an empty fragment identifier, as in go to a named anchor
but I'm not giving you the name of that named anchor.

action='' is usually the currently viewed page. Some browsers interperet #
as being 'the top of the page'.

But then again as per the specification relating to action on a form
element - "User agent behavior for a value other than an HTTP URI is

Quoted text here. Click to load it

I would not do that.


Re: form action="#"

rf wrote:

Quoted text here. Click to load it

That does not contradict what Scott wrote. So you are both right.

And you are both wrong, since "#" is the same as the base URL of the page,
and while this defaults to the current page URL, it can also be set in a
<base href="..."> tag.

Quoted text here. Click to load it

The question was not about action='' (which would a somewhat interesting
question theoretically, but it wasn't asked).

Quoted text here. Click to load it

Have you got evidence about browsers that do _not_ interpret it according to
the specification?

Quoted text here. Click to load it

Now guess whether "#" is an HTTP URI. You may guess twice. The correct
answer is, of course, "It depends". Can you figure out what it depends on?

Quoted text here. Click to load it

You don't have to do that. But that doesn't constitute a serious objection
to the idea.

Perhaps more commonly, action="#" is used for technical validity reasons for
forms that are "JavaScript-driven", i.e. all handling takes place
client-side and the form is not to be submitted to a server ever.


Re: form action="#"

On Tue, 12 May 2009, Jukka K. Korpela wrote:

Quoted text here. Click to load it

It is by no means an unusual construction that a form sends the data to
itself, even if no JavaScript is involved and everything is done by the
server. The logic of the form is "check for completeness, complain about
wrong input, and do what is wanted if everything is complete and correct".
Initially, the form is incomplete and without errors, and with each try of
the user it is supposed to get more complete (and sometime more
erroneous). It is the simplest way to ask the user back if his input is
incomplete or erroneous -- and no client-side code needs to be involved.

Helmut Richter

Re: form action="#"

Jukka K. Korpela:

Quoted text here. Click to load it

Interesting. It depends on what the HTML spec means by HTTP URI. And what
it means is not at all clear to me.

Fragment identifiers weren't part of URIs in RFC 2396, but the HTML spec
uses URI to mean URI Reference, which did include fragment identifiers.

If it means URI, in terms of RFC 2396, then the behaviour is unspecified,
since <#> isn't a URI. If it really means URI Reference, <#> is allowed.

But if <#> is allowed, the spec is wrong, because section 17.13.3 would
lead to monstrosities like <#?foo=bar>.

The browsers I tried, for what it's worth, kept the fragment identifier to
the end of the new URI. Error recovery or ignoring the spec, I don't know.


Site Timeline