I have a very basic script that calculates and changes the width of a div but its not working it keeps giving a 100 % result .
My script is like this:
<script>
var hp = <? echo $row['hp']; ?>;
var max = <? echo $row['maxhp']; ?>;
var perc = Math.round(hp/max * 100);
if(perc > 100) perc = 100;
else if(perc < 0 ) perc = 0;
d = document.getElementById('health');
d.style.width= perc+"%";
</script>
<div id="health" style="background-color:green;min-height:5px;"></div>
The PHP numbers are showing correct in the JS as:
var hp = 500;
var max = 2500;
Any ideas why it might not be working ?