I been having an issue with my JS not doing as its told ! For ages i couldn't work out why but now i realise my script infact works fine, its actually related to my AJAX calling the script.
The page which gets the file and displays it - is where it displays incorrectly. If i access the script normally it is working perfectly fine.
Is there something to do with AJAX requests that can cause this issue :S ?
See here for the effect.
This image is correct:
http://i39.tinypic.com/34fdvu8.jpg
This is wrong (which is the same script just called via ajax and displayed):
http://i43.tinypic.com/2uysl6b.jpg
The red bar is fine.. the broke part is the fact the green bar comes out at 100% in the ajax request one but comes out at 20% when viewing the script directly (20% is the correct answer).
Any ideas why this might be ?
<head>
<script type="text/javascript">
function percentage(){
var perc = Math.round((500 / 2500) * 100);
if(perc > 100)
{perc = 100;}
else if(perc < 0 )
{perc = 0;}
d = document.getElementById('health');
d.style.width = perc + "%";
};
onload = percentage;
</script>
</head>
<body>
<div style="width:50%;background-color:red;min-height:15px;">
<div id="health" style="background-color:green;min-height:15px;"></div>
</div>
</body>