/    Sign up×
Community /Pin to ProfileBookmark

Problem posting table elements to a PHP scfript for a table created in javascript

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 $_POST[“jobidN”] (where N is an integer) are always empty.
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>[/CODE]

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>”;
}
?>[/CODE]

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[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootJun 12.2017 — Please don't double post.
×

Success!

Help @kwatts59 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...