Jump to content

Buttons outside of form elements


End User

Recommended Posts

Is it "legal" to use a 'button' element outside of a form? Not a regular 'submit' button, but an actual 'button' element, i.e. <input type="button" id="foo"... etcThe reason I ask is because the documentation I've found is a little hazy. The w3.org page on buttons shows a button inside a form, but doesn't state that it *must* be inside a form: http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTONIn fact, it seems to make a distinction regarding in what it calls a "successful control", where it says that "controls outside a form cannot be successful controls". The section on "successful controls" says in part, A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.. It seems by "successful control" they mean a control that will submit information when the form is submitted. But, a button doesn't have to be used for submission purposes, it may just be used to adjust other controls that are within the FORM element. The button(s) I want to use aren't intended to submit data, they just load text inputs or other settings to form elements that will be submitted. I've seen tons of buttons used outside of forms this way and obviously they work (that is, they do what the designer wants them to do), but I still can't tell if it's actually a "legal" requirement in terms of markup for them to be enclosed in a set of FORM tags.So...does anyone know for certain whether or not buttons have to be inside form tags?

Link to comment
Share on other sites

No, buttons don't have to be in a form, but when it comes to accessibility, they're only useful for Javascript when outside a form and won't do anything if Javascript is disabled.

Link to comment
Share on other sites

The purpose of a form is to submit data to a server. If a form is not doing this, the element would be unsemantic, and putting controls in such a form would compound the sense of unsemanticism. In other words, leave the form tags out. It's okay, and it validates.The use of form controls for purposes unrelated to form submissions has a long tradition. Now of course it is extended with AJAX, which bypasses the form mechanism entirely. (Yes, some AJAX apps can gracefully degrade to a form submission, but not all.)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...