I am producing a dynamic table based on the result of an ajax call. I must change the background colour of one cell depending on the result of the if
statement.
Does anyone know how this can be done.
My code for producing the table
var today = "<?php echo $Today;?>";
var enddate = todate + " " + totime;
console.log("End date", enddate);
var tr_str = "<tr class='TableText'>" +
"<td style='color:#333;font-size:0.8em;'>" + promotionname + "</td>" +
"<td style='color:#333;font-size:0.8em;'>" + deviceid + " " + screenlocation + "</td>" +
"<td align='center' style='color:#333;font-size:0.8em;'>" + orientation + "</td>" +
"<td style='color:#333;font-size:0.8em;'>" + promotionimage + "</td>" +
"<td align='center' style='color:#333;font-size:0.8em;'>" + mediatype + "</td>" +
"<td style='color:#333;font-size:0.8em;'>" + fromdate + "</td>" +
"<td style='color:#333;font-size:0.8em;'>" + todate + "</td>" +
// HOW CAN I PLACE AN IF STATEMENT HERE
if (enddate < today) {
"<td align='center' style='color:#333;font-size:0.8em;' class='Complete'>Complete</td>" +
} else {
"<td align='center' style='color:#333;font-size:0.8em;' class='Scheduled'>Scheduled</td>" +
}
"<td align='center' style='color:#333;font-size:0.8em;'><input type='button' name='edit' value='Edit' id=" + (i + 1) + " class='btn btn-info btn-xs btn-block edit_data'></td>" +
"</tr>";
$("#userTable tbody").append(tr_str);
Many thanks in advance for your time and help.