setInterval works when alert is included in if conditions, else it works only once.

setInterval works when alert is included in if conditions, else it works only once.

Hi All,

My question is following : I have code snippet as follows :

 
  1.     var i = 0;               
  2.  
  3.     function func2() {                   
  4.     if (i==0){ 
  5.  
  6.     document.getElementById('frame1').contentWindow.opts[selected].setAttribute('name','channels'); 
  7.     var strValue = document.getElementById('frame1').contentWindow.opts[selected].getAttribute('name'); 
  8.    //alert("Attribute value set :" + strValue); 
  9.    document.getElementById('frame1').contentWindow.handleKeyCode(VK_ENTER); 
  10.    i++; 
  11.  
  12.    } 
  13.    else if(i==1){ 
  14.  
  15.    // For Channels section -- "Get current channel details" 
  16.    document.getElementById('frame1').contentWindow.opts[selected].setAttribute('name','get'); 
  17.    var strValue = document.getElementById('frame1').contentWindow.opts[selected].getAttribute('name'); 
  18.    //alert("Attribute value set :" + strValue); 
  19.    document.getElementById('frame1').contentWindow.handleKeyCode(VK_ENTER); 
  20.    i++; 
  21.  
  22.    } 
  23.    else if(i==2){ 
  24.  
  25.    // For Channels section -- "Set current channel details" 
  26.    document.getElementById('frame1').contentWindow.opts[selected].setAttribute('name','set'); 
  27.    document.getElementById('frame1').contentWindow.menuSelect(1); 
  28.    var strValue = document.getElementById('frame1').contentWindow.opts[selected].getAttribute('name'); 
  29.    //alert("Attribute value set :" + strValue); 
  30.    document.getElementById('frame1').contentWindow.handleKeyCode(VK_ENTER);      
  31.    i++; 
  32.  
  33.    } 
  34.    } 
  35.  
  36.    $(function() { 
  37.       setInterval(function(){func2();}, 1000); 
  38.    }); 

In this the setInterval works only once i.e it executes only the first if condition. But as I enables the "alert" messages of all the conditions then the setInterval works fine.

I don't want the "Alert Messages" for this setInterval if conditions, it should execute each if elseif statment as per the condition and at given time interval.

I am unable to achieve this. Also i didn't find any satisfactory reference from the setInterval related questions in this forum. Please help.

Thanks.