Friday, March 14, 2008

for loop problem in IE

I was coding some small javascript which should change the tab and modify some color and stuff and load some rss from somewhere its no big deal. somehow code worked in firefox but not in ie7. first I tought I manage to broke variables and naming. look at the code:

function ChangeTab(id,title){
for(k=1;k<4;k++){
if(k==id){
// section 1
}
else
{
// change like it did not choosed
}
}
}

its the simplest code ever. but somehow in ie it did not throw any debug dialog or any error at all. it was breaking the for loop "section 1" if it goes in there. here is the solution:
function ChangeTab(id,title){
for(var k=1;k<4;k++){
if(k==id){
// section 1
}
else
{
// change like it did not choosed
}
}
}

looks like no difference isnt it :) look closer. ie's javascript engine wants that k has to be declared there strange very strange. because normally ie can handle this small things. anyway what is the lesson from here. never trust ie :)

1 comment:

Anonymous said...

Hello. This post is likeable, and your blog is very interesting, congratulations :-). I will add in my blogroll =). If possible gives a last there on my blog, it is about the Home Theater, I hope you enjoy. The address is http://home-theater-brasil.blogspot.com. A hug.

odd string diff

 https://leetcode.com/problems/odd-string-difference/ Beats 19.92% of users with Java   class Solution { public String oddString ( S...