0

Hi guys, I was wondering whether it is alwasy true that a button needs to be inside a form tag? Is that necessary all the time?

The W3C say that The FORM element acts as a container for controls

so kind of yes really, but I 'd like to see if anybody has a different opinion. The thing is, I am working on a simple page at th moment which has 3 buttons, each of them doing a different thing: the first button validates something online; the second validates something offlice; the third cancels the action. So ideally each of them should be inside a separate form tag don't you think? To save me the hassle of having 3 form tags I was thinking not to have it at all, so just buttons inside a container, no form tag involved, but I am not sure that is a good idea

4
Contributors
6
Replies
19
Views
4 Years
Discussion Span
Last Post by Meir David
0

If you remove the form tag you'll just have to trigger your actions with Javascript. Depending on what you need to do this may be just fine.

0

pritaeas, I think I might have made a mistake in the way I have formulated the question. It didn't occur to me (yes I must have forgotten!) that buttons tag can have a type="button" which in a way it solves the problem. So really my question should have been: can I have more than 1 submit button inside a form tag? From what I can see, yes I can as long as they have a different name attribute. SOrry for the confusion.

0

Yes, you can. They will all share the same form action of course. If they need to be different, you'll have to use some Javascript.

0

ok I see, how about more than one submit button with a different name attribute? would that be enough to somehow "differentiate" them?

1

Server side, yes. Only the submit button that was clicked will be set in the POST data.

-1

Hi,your question might confusable can you explain it clearly so that it will be easy for me to give you solution....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.