crescue
asked on
How to get a value from a generated PHP table
Hi, I am populating a table using php. How can I get the value of 'JOB' from the table where the user clicks the checkbox. I have tried to add a class like previously suggested, but I cannot make it work. I am attaching my code
while($row = $result->fetch_assoc()) {
printf("<tr><id='traba'><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><input class='boxtocheck' type='checkbox' id='editar' name='editar' value='".e."' ><td></tr>",$row["fecha"], $row["job"],$row["tipo"],$row["valor"],$row["dinero"],$row["editar"]);
$total=$total+$row["valor"];
$total2=$total2+$row["dinero"];
$jobs=$jobs+1;
}
} else {
echo "0 results";
}
<script>
$(document).ready(function()
{
$('.boxtocheck').change(function()
{
if(this.checked === true)
{
// I am trying to see if the correct value is posted y1 = document.getElementById('traba').value;
// console.log(y1);
alert('Load page to edit');
}
});
});
</script>
replace :
<input class='boxtocheck' type='checkbox' id='editar' name='editar' value='".e."' >
by :<input class='boxtocheck' type='checkbox' id='editar' name='editar' value='".e."' data-job='" . $row["job"] . "' >
so :<script>
$(document).ready(function()
{
$('.boxtocheck').change(function()
{
var job = $(this).data("job"); // you get the job
if(this.checked === true)
{
// I am trying to see if the correct value is posted y1 = document.getElementById('traba').value;
// console.log(y1);
alert('Load page to edit');
}
});
});
</script>
ASKER
I guess I confused you by entering value='".e."' I left that value because I saw it when I google it on how to do it
My purpose is to get the value of 'JOB', and is always a different value based from the database
Tnx
My purpose is to get the value of 'JOB', and is always a different value based from the database
Tnx
Have you tried my solution?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, that was exactly what I was looking for !!! Tnx for your solution Pluritechnician, but I was trying to give point to Chris Stanyon too because of his great description on the SOLUTION, but I couldn't find where to split points :-(
Tnx to BOTH experts !!!
Tnx to BOTH experts !!!
Open in new window