HI all,
I am having problems posting table elements to a PHP script for a table updated in javascript.
When the user clicks on a button, the check_job_status function gets called (see code below) that adds rows to a predefined table (job_table). There are 3 elements per row, a job id, a job description and a check box. When the user clicks on the submit button, a PHP program gets called (cancel_jobs.php). In the PHP program, the $_POST[“checkN”] variables are getting set, but the $
The problem must be in how the job id cells are created.
If anybody knows what I am doing wrong, it would be greatly appreciated.
Thanks
Here is the javascript program:
[CODE]<script>
function check_job_status() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var jobs = this.responseText;
var job_strings = jobs.split(“n”);
var num_jobs = job_strings.length – 1;
var table = document.getElementById(“job_table”);
for (var index = 0; index < num_jobs; index+=1) {
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var job_cells = job_strings[index].split(“:”);
// Job ID
job_cell = row.insertCell(0);
job_cell.innerHTML=job_cells[1];
job_cell.id = “jobid”+index;
job_cell.name = “jobid”+index;
/* I also tried the following but it still did not work
var job1=document.createTextNode(job_cells[1]);
job1.id = “jobid”+index;
job1.name = “jobid”+index;
job_cell.appendChild(job1);
*/
// Job description
row.insertCell(1).innerHTML= job_cells[2];
// Check box
check_cell = row.insertCell(2);
var chk1=document.createElement(“input”);
chk1.type = “checkbox”;
chk1.id = “check”+index;
chk1.name = “check”+index;
check_cell.appendChild(chk1);
} //endfor
divwin=dhtmlwindow.open(‘divbox’, ‘div’, ‘somediv’, ‘Job Status’, ‘width=450px,height=300px,left=200px,top=150px,resize=1,scrolling=1’);
}
}; //end function
xmlhttp.open(“POST”, “check_status2.php” , true);
xmlhttp.send();
} //end check_job_status
</script>
Here is the check_status2.php program:
[CODE]<?php
if (empty($_POST[“check0”]))
{ echo “No check0<br>”; }
else
{
$chk0 = $_POST[“check0”];
echo “Got check0 $chk0<br>”;
}
if (empty($_POST[“check1”]))
{ echo “No check1<br>”; }
else
{
$chk1 = $_POST[“check1”];
echo “Got check1 $chk1<br>”;
}
if (empty($_POST[“check2”]))
{ echo “No check2<br>”; }
else
{
$chk2 = $_POST[“check2”];
echo “Got check2 $chk2<br>”;
}
if (empty($_POST[“jobid0”]))
{ echo “No jobid0<br>”; }
else
{
$jobid0 = $_POST[“jobid0”];
echo “Got jobid0 $jobid0<br>”;
}
if (empty($_POST[“jobid1”]))
{ echo “No jobid1<br>”; }
else
{
$jobid1 = $_POST[“jobid1”];
echo “Got jobid1 $jobid1<br>”;
}
if (empty($_POST[“jobid2”]))
{ echo “No jobid2<br>”; }
else
{
$chk2 = $_POST[“jobid2”];
echo “Got jobid2 $jobid2<br>”;
}
?>
And here is the output when the “submit” button is clicked when the first and third job are checked. Note that a value for check0 and check2 were posted but no jobids were posted.
[CODE]Got check0 on
No check1
Got check2 on
No jobid0
No jobid1
No jobid2