i've looked around and did no find an answer to a question that has been bugging me for quite some time. let's say i have a mysql table with tasks. in php i loop through all the records and display them. each row should have buttons e.g. "done", "delete", etc. which will trigger an action (preferably with ajax).
now the question is, should i do this with multiple forms or just with one? is there a best practice for that? are there considerable advantages/disadvantages for each of the options?
i did search on this site, so my apologies in advance, should i have missed a post explaining just that.
thanks a lot in advance
This is how I would write it. I don't see the need for forms. I think forms might slightly over complicate the process.
<ul>
<li mysqlId="0">Name <button class="done">Done</button> <button class="delete">Delete</button></li>
<li mysqlId="1">Name <button class="done">Done</button> <button class="delete">Delete</button></li>
</ul>
<script>
$(".done").click(function () {
mysqlId = $(this).parents("li:first").attr("mysqlId");
$.post(/* ajax magic */);
});
$(".delete").click(function () {
mysqlId = $(this).parents("li:first").attr("mysqlId");
$.post(/* ajax magic */);
});
</script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments