We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,858 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Open a JQuery modal dialog box on a certain variable value

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?

2
Contributors
2
Replies
17 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
emulman
Newbie Poster
15 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

'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.

ko ko
Practically a Master Poster
673 posts since Jan 2009
Reputation Points: 120
Solved Threads: 152
Skill Endorsements: 1

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!

emulman
Newbie Poster
15 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0605 seconds using 2.69MB