Possible Duplicate:
Can I change the <td> background if a field result is great or equal to another field?
Trying to get my script to work, displaying mySQl results in an HTML table via php with a particular column TD that contains $qty that needs to have its background turn red when it equals or passes $min or $max.
Maybe there’s a better way to right this php?
Script is not working.
<script type="text/javascript">
$(document).ready(function() {
var min = parseInt($('.min').text());
var max = parseInt($('.max').text());
var qty = parseInt($('.quantity').text());
if (qty >= max || qty <= min ) {
$('.quantity').css('background-color', 'red');
}
});
</script>
My php table / the three fields are toward the end of the table:
$o .= '<tr><td>'.$type.'</td><td>'.$part_no.'</td><td>'.$description.'</td><td>'.$artwork.' </td><td><a href="/data/hero/copies/'.$part_no.'.pdf" target="_blank">Link </a></td><td align=right class="min">'.number_format($min).'</td><td align=right class="max">'.number_format($max).'</td><td align=right class="quantity">'.number_format($qty).'</td></tr>';}
Your php sample has a stray
}at the end of the line. Is that causing this issue?I’ve just tried this with the javascript you posted and this php:
It works perfectly.
Is
$ogetting properly printed out to the browser? If you view the HTML source, do you have atds with the classes min, max and quantity? What exact symptoms of it not working do you get? Maybe you could post a little more of the script?