in a my page i have create che code for a modal dialog box in jquery:

<script type="text/javascript">
  $(document).ready(function() {
    $('#dialog').dialog({
      autoOpen: false,
      height: 280,
     modal: true,
      resizable: false,
      buttons: {
        OK: function() {
          $(this).dialog('close');
        }
      }
    });
  });
</script>

i should want the window appears if a condition isn't found in a PHP page, for example

if ($user->username) {
    if ($user->password1) {
      if ($user->password2) {
        if ($user->password1 == $user->password2)
          $user->save();
        else
          echo $user->message("password aren't equals!");
      } else
          echo $user->message("password 2 isn't inserted!");
    } else
        echo $user->message("password 1 isn't inserted!");
  } else
      echo $user->message("username isn't present!");

where MESSAGE is a public function like this:

public function message($text) {
  $script = "<div id=\"dialog\" title=\"warning\">" . $text . "</div>";
  $script = "<script type=\"text/javascript\">$('#dialog').dialog('open')</script>";
  return $script;
}

but this code doesn't work..why? i should open the box only with a click event for example?

Recommended Answers

All 2 Replies

'dialog' is the plugin, and all are properties and values within ({}) following 'dialog', not variables.

I don't know what does the plugin suppose to do. Perhaps, you need to configure the setting correctly.

$('#dialog').dialog('open')

Should be

$('#dialog').dialog({autoOpen: true});

Or put the method of the plugin that does the dialog box appear, instead of 'autoOpen', and proper value separated by colon.

And you need to embed the plugin js file in your document. For example:

<script type="text/javascript" src="../path/jquery-dialog-plugin.js"></script>

Better if you post the code inside the plugin js file.

Hope this help.

nothing...i have tried also another method: and if i simulate a click event on the modal box via trigger() to open it? for this i have modified the script in the HEAD section:

<script type="text/javascript">
	$(document).ready(function() {
           $('#dialog').dialog({
             autoOpen: false,
             height: 280,
             modal: true,
             resizable: false,
             buttons: { OK: function() { $(this).dialog('close'); } }
          });
          $("#dialog").click( function() { $(this).dialog('open'); });
       });
  </script>

then i have modified the PHP function

public function message($text) {
      $script = "<div id=\"dialog\" title=\"warning\">" . $text . "</div>";
      $script .= "<script type=\"text/javascript\">\$('#dialog').trigger('click')";
      $script .= "</script>";
      return $script;
    }

so when i found a PHP line code like

echo $utils->message("cannot connect to database!");

must shows the modal box with the message; practically the event click is "open it" trigger function simulates a click on the modal box which event click is "open the modal box"..but nothing, it doesn't appear!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.