I need to make a table with clickable rows (for this I found some Javascript solutions).
When I click one row, a form will be filled with data from the clicked row.
But I don’t know how to send the data from HTML table to PHP, when I click on that row. Data must be sent as POST, as I mentioned in title.
I have no idea how to start, so I cannot show you nothing. Using multiple forms inside one table is not allowed, <a> tag around <td> is not allowed either, so I’m stuck.
From what I searched on web, the solution would be AJAX, but I’m not familiarized with it, never used AJAX, so if possible, a non-AJAX solution would be much appreciated. If not, please show me a functional example.
EDIT solved
In the end I did it without any AJAX, thanks to ideas from emartel and Guerra.
I made a single form with a hidden input field and I submitted it programatically, after I collected the required data from the row I clicked on.
I echoed the tr tags like this: <tr data-id=$id_from_db onclick="submit_id(this)">.
function submit_id(tableRow) {
//get ID
var myID = tableRow.dataset.id;
//set ID
var setID = document.getElementById('order_id');
setID.value = myID;
//submit
var form = document.getElementById('myform');
form.submit();
};
P.S. I tried to embed some PHP code, but I failed, it didn’t shown on page.
After filling your form (
name="myform"andmethod="post") from JavaScript, simply call:This should do the work