Skip to content
Advertisement

How to get id of submit type button, when button is pressed

I want to print out the id of the button I pressed. The id is set dynamically for each button in a table. This is my HTML code:

JavaScript

And I want to print the id of the button here.

JavaScript

Advertisement

Answer

If you do not wish to use a hidden field, you could set your submit button like this:

JavaScript

Then you can catch it with $_GET['id'].

You can have many buttons of type="submit" with the same name (id), and the value will be the one which was clicked, or the first one, if the form was submitted by pressing enter.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement