0

I want to trigger a dialog modal-message script inside a yes-no logic. Currently it works in a onclick event. Example: http://jqueryui.com/dialog/#modal-message

I want this to execute automatically (without any click) if my logic is true.

Example:

if Logic is true Then Execute

<script>
$(function() {
  $( "#dialog-message" ).dialog({
    modal: true,
    buttons: {
      Ok: function() {
       $( this ).dialog( "close" );
      }
    }
  });
});
</script>

Any idea?

2
  • do you want to run it on page load? or on some other event? Commented Sep 1, 2014 at 10:38
  • Just make that a function and call it. Commented Sep 1, 2014 at 10:38

2 Answers 2

2
<script>
$(function() {
  $( "#dialog-message" ).dialog({
   modal: true,
   buttons: {
      Ok: function() {
         $( this ).dialog( "close" );
      }
   }
  });

  if ( condition ) 
     $( "#dialog-message").dialog('open');
});
</script>

That's how you can call it with a condition.

Sign up to request clarification or add additional context in comments.

1 Comment

Isn't that initialising a new dialog? I mean, without any properties set.
1

Why not

<script>
var myFunc = $(function() {
    $( "#dialog-message" ).dialog({
        modal: true,
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
           }
       }
    });
});


$(document).ready(function() {
    // Edit after comments
    $(document).on('some-selector', 'some-event', function() {
        if (/* your logic is true */) {
            myFunc();
        }
    }
 });

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.