CodingOdd JavaScript Bug

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  Peter (BOUGHTONP)  
 To:  ALL
30698.1 
Here's a function:
javascript code:
function totalCost(currency)
{
//	alert(currency);
	elem('total_cost').innerText = currency+' '+Math.round((cost.main+cost.pp+cost.wwpap+cost.icp)*100)/100;
	setTimeout("alert(elem('total_cost').innerText)",0);
}


The setTimeout(...,0) just means execute immediately. In this form, everything works fine.

If I change it from 0 to 1 — ie: execute the alert after one millisecond — or if I simply comment out the alert, then Internet Explorer cries. with the message "Internet Explorer cannot open the Internet site {url} Operation aborted", before changing to the incredibly helpful "Cannot find server or DNS Error
" generic error page.

I can't figure out what's wrong, because all the code is perfectly fine and runs with no errors on FF (or with the alert), and I have even less of an idea why the alert prevents IE from throwing its tantrum.

Anybody have any suggestions?
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ALL
30698.2 In reply to 30698.1 
Bah, I had a feeling I'd posted something like this before, and I have. ( msg:30246.1 )

Used the same solution as there and it's working now.

Fucking IE! :@
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ALL
30698.3 In reply to 30698.2 
It's broken again. :@

But only on some loads. :@ :@

:@ :@ :@
0/0
 Reply   Quote More 

 From:  Ally  
 To:  Peter (BOUGHTONP)     
30698.4 In reply to 30698.1 
quote:
The setTimeout(...,0) just means execute immediately. In this form, everything works fine.


Not putting it in a SetTimeout would do exactly the same thing?

And I've not seen the other thread, but try:

code:
setTimeout(eval("alert(elem('total_cost').innerText)"),0);


or

code:
setTimeout(new function() {alert(elem('total_cost').innerText)},0);
0/0
 Reply   Quote More 

 From:  Matt  
 To:  Ally     
30698.5 In reply to 30698.4 
code:
Not putting it in a SetTimeout would do exactly the same thing?


It's not. By calling a function with SetTimeout you don't interrupt the code flow following the call which means you can pretty much have have two functions running at the same time. It's like a half-arsed attempt at threading except it's not because Javascript doesn't do threading.

doohicky

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  Ally     
30698.6 In reply to 30698.4 
Well, what Matt says is right, but yeah it works without the setTimeout just like with it at 0.

It's working consistantly now though (with a 50ms setTimeout on the calling function instead), so it possibly might have been a JS caching issue earlier.
0/0
 Reply   Quote More 

Reply to All    
 

1–6

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats