The following code divides 'invites' by 'accepts' and then rounds it to 2 decimal places, always keeping 2 decimal places even if the answer is 8.00
This is the code I am using:
function live_ratio()
{
// Check that the invites, accepts, and ratio spans have loaded
while(!document.getElementById("live_invites").innerHTML || !document.getElementById("live_accepts").innerHTML || !document.getElementById("live_ratio").innerHTML)
{
//alert('blah');
document.getElementById("live_ratio").innerHTML = (Math.round(document.getElementById("live_invites").innerHTML / document.getElementById("live_accepts").innerHTML * 100) / 100).toFixed(2);
}
}
For some reason, it doesn't work how it is now, it just doesn't invoke the document.getElementById("live_ratio").innerHTML line, and doesn't update the span. However, if I uncomment the alert() above, it works perfectly! :blink: Any ideas? Also, it has to be in the while() statement because the 3 id's it checks have loaded, are loaded via AJAX.
+1000 to this, don't understand why they added that margin around the top bar, even the close button is a PITA to click without aiming.
Ofc, this is just preview and hopefully they will revert such odd UX decision before hitting final version.
Question
-Alex-
The following code divides 'invites' by 'accepts' and then rounds it to 2 decimal places, always keeping 2 decimal places even if the answer is 8.00
This is the code I am using:
function live_ratio() { // Check that the invites, accepts, and ratio spans have loaded while(!document.getElementById("live_invites").innerHTML || !document.getElementById("live_accepts").innerHTML || !document.getElementById("live_ratio").innerHTML) { //alert('blah'); document.getElementById("live_ratio").innerHTML = (Math.round(document.getElementById("live_invites").innerHTML / document.getElementById("live_accepts").innerHTML * 100) / 100).toFixed(2); } }For some reason, it doesn't work how it is now, it just doesn't invoke the document.getElementById("live_ratio").innerHTML line, and doesn't update the span. However, if I uncomment the alert() above, it works perfectly! :blink: Any ideas? Also, it has to be in the while() statement because the 3 id's it checks have loaded, are loaded via AJAX.
Thanks all!
Link to comment
https://www.neowin.net/forum/topic/705392-js-simple-function-not-working-unless-i-do-alert-first/Share on other sites
13 answers to this question
Recommended Posts