Reputation: 39501
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();
}
Upvotes: 0
Views: 267
Reputation: 8784
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();
}
Upvotes: 0
Reputation: 700252
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();
}
Upvotes: 1