tags:

views:

88

answers:

2

I have a page with one continue button. If I click on continue then all the above 3 popups come on after the other if I click OK for the popups, but if I click Cancel on a popup then the page should get closed, which is done by my closeAction(); method.

If I click cancel for the 1st or 2nd popups the page is not being closed, but the 3rd works.

if(document.getElementById(id1).value){
    if(!confirm("click Cancel to Close page and ok to go to next popup")){
         closeAction();
    }
       }

if(document.getElementById(id2).value){        
       if(!confirm("click Cancel to Close page and ok to go to next popup")){
     closeAction();
    }
       }
if(!confirm(" to be made click 'Cancel'")){
       closeAction();
         }
+1  A: 

Use else, so that you skip the rest of the checks once you called the closeAction method:

if (document.getElementById(id1).value && !confirm("click Cancel to Close page and ok to go to next popup")) {
   closeAction();
} else if (document.getElementById(id2).value && !confirm("click Cancel to Close page and ok to go to next popup")) {
   closeAction();
} else if (!confirm(" to be made click 'Cancel'")) {
   closeAction();
}
Guffa
but all the popus should come
Sunny Mate
@suresh: Even if you click cancel on the first?
Guffa
A: 

Remember, && is short-circuiting:

if (document.getElementById(id1).value &&
    !confirm("click Cancel to Close page and ok to go to next popup") &&
    document.getElementById(id2).value &&
    !confirm("click Cancel to Close page and ok to go to next popup") &&
    !confirm(" to be made click 'Cancel'"))
{
    closeAction();
}
Anthony Mills