I'm working with PHP and Javascript. I return arrayList from PHP file to PHP web page; in the PHP web page I want to display array list in a table, but one of the fields "state" can be "Success or Rejected", if success, the td table shows span bootstrap icon, else, also. I using Javascript function for return span icon, but it can't read param "state" to invoke function.
My js file:
function getStateIcon(strState) {
var strHtml = '';
if (strState === "Success") {
strHtml = '<span class="label label-success">' + strState +'</span>';
} else if (strState === "Rejected") {
strHtml = '<span class="label label-warning">' + strState + '</span>';
}
return strHtml;
}
And my php web page:
<table>
//headers.....
//body
<?php
include_once '../../Model/RequestDto.php';
$list = new ArrayObject();
if (isset($_SESSION["list"]) == null) {
echo 'not found results';
} else {
$list = $_SESSION["list"];
foreach ($list as $val) {
?>
<tr>
<td><?php echo $val->getID?></td>
<td><?php echo $val->getDate()?></td>
<td><script type="text/javascript">getStateIcon(<?php echo $val->getState()?>);</script></td> //here i want pass parameter state to the js function for return span icon and draw td, but this show empty
</tr>
<?php
}
}
?>
</tbody>
</table>