Getting the value of a clicked button from a list of submit buttons
Posted on 2014-04-24
I display rows of mySQL records with two buttons - Edit and Delete, at the end of each row. A user is supposed to click either edit or delete of a chosen row and be presented with the contents of the chosen record on a form. She/he can then edit the contents of the form and submit or delete as the case may be.
I use ajax/jquery to retrieve the value of the clicked button and php to process the input. I am having hard time displaying the records appropriately and retrieving the value of the selected button using ajax/jquery. Once retrieved I would use php to process it and display a confirmation message in a div.
1. Is it better to have a separate form for each pair of edit/delete buttons? Would that mean a unique id for every form to distinguish it from the rest? That is, if on form submit is to be used in ajax/jquery. OR
2. Use the same form for all the buttons and get the value of the clicked button (either edit or delete) and the record id associated with it?
3. How would the html/php code to list the mySQL records and the ajax/jquery code retrieve the values look like?
Your quick help is deeply appreciated.