DEV Community

Cover image for HTML : You can distinguish if the form button pressed
Rajesh Kumar Yadav
Rajesh Kumar Yadav Subscriber

Posted on

HTML : You can distinguish if the form button pressed

Most of us are unaware of the fact that we can distinguish if the form button pressed by just giving them a name/value pair as shown below -

<form action="process" method="post">
     ...
     <input type="submit" name="edit" value="Edit">
     <input type="submit" name="delete" value="Delete">
     <input type="submit" name="vote_up" value="Vote up">
     <input type="submit" name="vote_down" value="Vote down">
</form>
Enter fullscreen mode Exit fullscreen mode

In the server side, the actual button pressed can then be obtained by just checking the presence of the request parameter associated with the button name. If it is not null, then the button was pressed.

Above code is just to explain you about this html hidden feature however you can use button tag instead.

Buy Me A Coffee

With all that being said, I highly recommend you keep learning!

Thank you for reading this article. Please feel free to connect with me on LinkedIn and Twitter.

Top comments (0)