3

Given the following form:

<form action method="post" onsubmit="func(this)">
    <button type="submit" value="prev"  >prev</button>
    <button type="submit" value="next"  >next</button>
    <button type="submit" value="submit">submit</button>
    <button type="reset"  value="reset" >reset</button>
</form>

Within func(), how to identify which button submitted the form?

spenibus
  • 4,339
  • 11
  • 26
  • 35
ashu
  • 579
  • 2
  • 6
  • 17

1 Answers1

2

You are doing it wrong. You can attach click event to each button and take action. This is cleanest way.

<button onclick="alert('You are clicking on me');">Reset</button>

Instead of alert insert your custom function. You can make it more robust by not using inline javascript. In those functions you can choose if you want to submit form or not by preventing or passing default event. Like event.preventDefault()

Mateusz
  • 2,287
  • 20
  • 28