what do and do?

I'm reading a book on html development (which I'm fairly new at) and despite the fact that the book just had its 1st publishing one month ago (Nov. 2011), the author is an experienced coder and maybe using # for the action in a form is old school? Because I'm trying to get the gist of the sample code and I cannot find an explanation of form action="#" despite searching for

on google, on SO, and in www.w3schools.com. Anyone know what the # action means for forms? 37.7k 9 9 gold badges 187 187 silver badges 205 205 bronze badges asked Dec 6, 2011 at 4:14 SandHawkerTech SandHawkerTech 855 1 1 gold badge 8 8 silver badges 8 8 bronze badges

action specifies where the info will be sent. in the example you found that the form is probably being submitted with javascript

Commented Dec 6, 2011 at 4:18

That's seems like bad sample code, you almost never would need to do that. Even if you're using javascript to submit the form, hardcoding a bogus action is not necessary.

Commented Dec 6, 2011 at 4:19 The de facto standard documentation for forms is found on w3c's website Commented Dec 6, 2011 at 4:21 I just now found some form like is that valid? Commented Aug 18, 2018 at 6:40

4 Answers 4

Action normally specifies the file/page that the form is submitted to (using the method described in the method paramater (post, get etc.))

Thus, the form is submitted to the same page, which then processes the data etc.

26.1k 11 11 gold badges 75 75 silver badges 104 104 bronze badges answered Dec 6, 2011 at 4:17 8,719 4 4 gold badges 25 25 silver badges 24 24 bronze badges

@Nik because some times your server actions are simple enough to operate on one page. I use this often when building a simple database lookup page in PHP. It's simpler than having two pages for your simple actions.

Commented Dec 6, 2011 at 4:19 The page just posts back to itself then? Commented Dec 6, 2011 at 4:21

exactly, although, I don't see how action="page.php" is different than action="#" (Assuming page.php is the current page) Both end up refreshing the page, consider ajax submission instead.

Commented Dec 6, 2011 at 4:22

@Nik that is correct. And on that page you build decision logic on whether to process posted input or just wait for the submit.

Commented Dec 6, 2011 at 4:22

I would use action="" to avoid confusion, since the point it to post to the page, not to an anchor on the page. However action="#results" might make sense.

Commented Mar 7, 2018 at 3:37

action="" will resolve to the page's address. action="#" will resolve to the page's address + # , which will mean an empty fragment identifier.

Doing the latter might prevent a navigation (new load) to the same page and instead try to jump to the element with the id in the fragment identifier. But, since it's empty, it won't jump anywhere.

Usually, authors just put # in href-like attributes when they're not going to use the attribute where they're using scripting instead. In these cases, they could just use action="" (or omit it if validation allows).