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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With