Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 747 characters in body
Source Link
Haibara Ai
  • 10.9k
  • 2
  • 35
  • 49

If you click a button with type="submit" in a form, by default browser will reload the page after the form is submitted.

To prevent the page reloaded, either removereplace type="submit" with type="button" or call e.preventDefault() inside sendValues handler.

Appendix:

According to MDN, the default value for button is submit.

type

The type of the button. Possible values are:

submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.

reset: The button resets all the controls to their initial values.

button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.

menu: The button opens a popup menu defined via its designated element.

If you click a button with type="submit" in a form, by default browser will reload the page after the form is submitted.

To prevent the page reloaded, either remove type="submit" or call e.preventDefault() inside sendValues handler.

If you click a button with type="submit" in a form, by default browser will reload the page after the form is submitted.

To prevent the page reloaded, either replace type="submit" with type="button" or call e.preventDefault() inside sendValues handler.

Appendix:

According to MDN, the default value for button is submit.

type

The type of the button. Possible values are:

submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.

reset: The button resets all the controls to their initial values.

button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.

menu: The button opens a popup menu defined via its designated element.

Source Link
Haibara Ai
  • 10.9k
  • 2
  • 35
  • 49

If you click a button with type="submit" in a form, by default browser will reload the page after the form is submitted.

To prevent the page reloaded, either remove type="submit" or call e.preventDefault() inside sendValues handler.