I have an array of prices that I output to a table with a foreach loop.
I'm trying to figure out how to hide rows in the table if a condition is met. The $status variable evaluates to "YES" if price is => 30 and "NO" if < 30.
<script type="text/javascript">
function displayRow(){
var row = document.getElementById("<?php echo $status;?>");
if (row.id == 'YES') row.id= 'none';
else row.display = '';
}
</script>
<?php
if($price > 30.00){
$status = "YES";
}else if($price < 30.00){
$status = "NO";
}
$prices = array ("20", "56", "33", "12", "66", "25", "55");
echo "<table border='1'>";
foreach ($prices as $price) {
echo "<tr id='$status'><td>$price</td></tr>";
}
echo "</table>";
?>
<button onclick="displayRow()" >Show / Hide</button>
I've tried setting the tr id with the appropriate status. So then in the Javascript function I try to pass the $status in to getElementById which should then display the prices that are > than 30 and hide those that are < 30.
The button is meant to toggle between display all the data or filter those prices > 30.
I know this is a very basic example and have probably made a lot of mistakes, but I'd appreciate any help.
Cheers
getElementsByClassNameorquerySelectorAll