jQuery return value to JavaScript

I am replacing the JavaScript standard confirm() dialog with a jQuery dialog.  I have no experience with using jQuery.

An excerpt of my code before the jQuery is this
      var confirmed = true;

      if(errors != "")
      {
         errors = warn1 + errors + "</ul>" + warn2;
         confirmed = confirm(errors);
         return confirmed;
      }
      return confirmed;

Open in new window


confirm gets the boolean value when the user clicks on OK or Cancel.
Then confirmed is returned and either the page submits (OK) or the user remains on the page (Cancel).

Now I'm substituting confirm() with the following:

         jConfirm(errors, 'Registration Errors', function(r) {
            jAlert('Confirmed: ' + r, 'Confirmation Results');
         });

Open in new window


I found the jConfirm dialog online at:
http://www.abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/

There is an example of the dialog at:
http://labs.abeautifulsite.net/archived/jquery-alerts/demo/
(see 2nd button "Show Confirm")

With the jQuery dialog, I do not want the 2nd dialog to popup when the user clicks OK or Cancel.  Instead, I want the true/false value to be returned to the JavaScript confirmed variable and then the rest should require no change.

If there is another way to have the same behavior (submit when OK, remain on page if Cancel), I'll take that as well.  I want the 1st dialog with the "errors" message to remain until the user clicks OK or Cancel.  I don't want the 2nd dialog (jAlert) to popup.
mock5cAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurvinder Pal SinghCommented:
you simply have to remove jAlert() call in the success handler

jConfirm(errors, 'Registration Errors', function(r) {
    if (r)
    {
            //invoke the 'ok' handler
    }
    else
    {
            //invoke the 'cancel' handler
    }
});
mock5cAuthor Commented:
Sorry, but as I said, I have no experience with jQuery.  Could you please provide an example of invoking the OK handler?

I've declared var confirmed outside the callback so wouldn't something like

jConfirm(errors, 'Registration Errors', function(r) {
confirmed = r;
});
Gurvinder Pal SinghCommented:
jquery solution is not a synchronous one, which will hold the execution of sequence of statements unless 'Ok' or 'Cancel' is clicked. So, this is why jConfirm uses callback handlers.

when i say 'invoke ok handler', i meant that you will invoke that code which you would have otherwise invoke when 'ok' would have been selected in the original javascript confirm box

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mock5cAuthor Commented:
I've been trying to create a little test with the following.  I can't get jConfirm to popup at all.  In fact, if I do a console.log("here") after the $('.form').on('submit', function() line, I don't see that in the console output.  

I am hoping this little example is on the way to doing what I described above,

<script>
$(function() {
$('.form').on('submit', function() {
    var $form = $this;
    var $err = "errors";
   jConfirm( err, 'Errors', function(r) {

    if (r) {
       $form('submit').off().submit();
    }
    else {
      return false;
    }
  });

  return false;
});
});
</script>

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.