skip to Main Content

<input type="button" name="justabutton" value="I'm just a button">

Will the value name pair of the button be sent in the the post request upon submitting the form?

I tried to use the input of button type as textinput by storing some data into its name attribute and pass it in the post body but couldn’t.

2

Answers


  1. Try this form. Before pressing "Run code snippet" open the dev tools in your browser and open the network tab. Try clicking both buttons and see what happens. The type="button" doesn’t do anything. The type="submit" does a GET request that looks like this: /post.php?justasubmitbutton=I%27m+just+a+submit+button.

    Conclusion

    The value of the type="button" is not send in the submit event, but the value of type="submit" will.

    <form name="form01" action="post.php">
      <input type="button" name="justabutton" value="I'm just a button">
      <input type="submit" name="justasubmitbutton" value="I'm just a submit button">
    </form>
    Login or Signup to reply.
  2. No, it won’t be sent in the POST request. The only button that’s automatically included in the post request is the submit button that you clicked on to submit the form (if the form is submitted due to pressing Return in the last text field, it’s as if you clicked on the first submit button).

    So the value of a button with type="button" will never be sent automatically.

    Use a type="hidden" input to pass extra values to the server, not a button.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search