3

I have seen people do:

<form ..>

  <button type='submit' value='Submit'>Sign Up</button>
</form>

Why do they need value='Submit' if it isn't even submitted to the server? Is it for accessibility?

platypus
  • 1,165
  • 5
  • 27
  • 47
  • 1
    That's not important, it should be left out. The `type` attribute is what matters, it says "Hey, I'm a button, and I'm gon' submit this form to the `form-action`" – DanielTheGeek Sep 24 '16 at 06:31
  • @DanielTheGeek — It doesn't really. `submit` is the default value. – Quentin Sep 24 '16 at 06:36
  • 1
    Why people do something that has no practical effect is really a matter of opinion / speculation. – Quentin Sep 24 '16 at 06:36

2 Answers2

0

Forms can have more than one submit button. If you also give each button a name, then you can use the value after submitting to see which one had been clicked.

<!DOCTYPE html>
<html>
 <head>
  <title>test submit</title>
 </head>
 <body>
  <form action="#" method="get">
   <button type='submit' name="clicked" value="thefirst">First</button>
   <button type='submit' name="clicked" value="thesecond">Second</button>
  </form>
 </body>
</html>

If you submit this with the first button, the parameter posted will be clicked=thefirst, while with the second one it will be clicked=thesecond.

Of course in this case a much saner approach would be to give the buttons different names. but you get the idea.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • 2
    Did you notice _if it won't be posted_ – Pravesh Agrawal Sep 24 '16 at 06:45
  • 1
    Sorry this does not answer the question of when there is only 1 submit button and there is no `name` field, but only a `value="Submit"` field. – platypus Sep 24 '16 at 06:50
  • @PraveshAgrawal I thought the OP meant the value of the button wasn't submitted when the button was clicked. Otherwise, why have a submit button at all. – Mr Lister Sep 24 '16 at 06:51
  • 1
    @platypus If there is no name, you can still retrieve the value with JavaScript during validation, so it would still have some use. Or, in the particular case you're talking about, it could be a leftover from when the ` – Mr Lister Sep 24 '16 at 06:56
  • @MrLister Actually question says why usually people write `value='Submit'` when it has no use to them. – Pravesh Agrawal Sep 24 '16 at 07:00
  • @PraveshAgrawal The other answer already tries to address why people would do something that doesn't have any use. But it is heavily downvoted, so I didn't go there in my answer; I concentrated on when the value _would_ be used. – Mr Lister Sep 24 '16 at 07:19
0

All programmer use this. Because its is good understanding to another programmer to review already written code. It is not compulsory.

Onic Team
  • 1,620
  • 5
  • 26
  • 37