-1

I am trying to avoid the confirm box of javascript and tried that jquery.ui dialog box.

When confirm box returns true or false after that only remaining javascipt will execute,but in this jquery.ui dialog that not happening.

This what i tried,

I am having some of the links

 function checkit(){
   var istrue = showdial("confirm");
   if(istrue== true) alert("yes");
   else  alert("no");
}
function showdial(tStr)
{
     $('<div></div>').appendTo('body')
                    .html('<div><h4>Are you sure..?</h4></div>')
                    .dialog({
                        title: tStr, 
                        zIndex: 10000,
                        autoOpen: true,
                        modal: true,
                        buttons:{
                             Yes: function(){

                                $(this).dialog("close");

                                return true;
                             }
                             No: function(){
                                $(this).dialog("close");
                                return false;
                              }
                        }

               }); 

  }

Please correct me if i did anything wrong above.

Before clicking that yes or no button it always alerts "no" only, . How can i run a script after that dialog returns an value. And i dont want that setTimeout() function to use.

Ramesh
  • 1,073
  • 6
  • 24
  • 53
  • Why don't you put your checkIt() logic by splitting what is needed in `Yes: function(){...} and No: function(){...}` assigned in your dialog – dchhetri Jan 19 '13 at 04:15
  • That also i tried,but if i pass some arguments to that yes function logic from checkit() its not working. – Ramesh Jan 19 '13 at 04:47

1 Answers1

2

Asynchronous code can't return values like that. Look at this related question which explains how to resolve this problem using callbacks.

Community
  • 1
  • 1
George
  • 4,147
  • 24
  • 33