• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Dynamically opening a dialog using jquery and php

Hi all,

I have jquery modal dialogs working well and executing on click events such as:

		$('#signupopen').click(function() {
			$signup.dialog('open');
			// prevent the default action, e.g., following a link
			return false;
		});

Open in new window


Now I'm having difficulty to get a dialogue to open when a php script does some work and then neds to spit out a 'success' dialog.

First I was thinking:

	if() // Criteria
	{
		//Update the db
		//DB UPDATE CODE
		
		//Call success window
		?>
		<script type="text/javascript">
		 
			$('#activate').dialog('open');
		 
		</script>		
		<?php
		
	}
	else
	{
	//Do nothing
	}

Open in new window


But nope, not that simple :)

Can anyone give me some pointers?

FYI - window code is loaded in prior to this script running:

		var $activate = $('#activate')
			.load('activation.php')
			.dialog({
				autoOpen: false,
				title: 'Activation Successful',
				draggable: false,
				modal: true,
				resizable: false,
				width: 420,
				height: 180,
				position: ['center',100]
				
			});

Open in new window


And the placeholder div just after the body tags:

<div id="activation"></div>

Open in new window


Huge thanks
0
dolythgoe
Asked:
dolythgoe
  • 3
  • 3
1 Solution
 
Darude1234Commented:
In the javascript you call the div 'activate':
$('#activate').dialog('open');

Open in new window

while your div is named 'activation':
<div id="activation"></div>

Open in new window


So just rename the div to activate, then it should be ok.
0
 
dolythgoeAuthor Commented:
Doh! That was a bit stupid - Thanks!

However, I've changed that and it still didn't work though :(

I wonder if it's something to do with the dynamic call - the php outputs the script but does that mean it should execute? Does something need to prompt it to run?
0
 
Darude1234Commented:
I've created an example for you here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title>Example for Q_27399152</title>
		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	  <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
	  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
	  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
	  
	  <script type="text/javascript">
	  $(document).ready(function() {
		$("#dialog").dialog({ autoOpen: false });
	  });
	  </script>
	</head>

	<body>
		<a href="#" onclick="$('#dialog').dialog('open');">Open dialog manually</a>
		<?php
		echo "<br />Executing some random code before the dialog appears<br />";
		for ($i = 1; $i < 10; $i++)
		{
			echo $i."<br />";
		}
		echo "Ready, now popup that dialog!";
		if ($i == 10)
		{
		?>
			<script type="text/javascript" language="javascript">
				$('#dialog').dialog('open');
			</script>
		<?php
		}
		?>

		<div id="dialog" title="Dialog Title">
			<?php 
				if ($i == 10)
				{
					echo "Completed succesfully!";
				}else{
					echo "Failed!";
				}
			?>
			
			<script type="text/javascript" language="javascript">
				$('#dialog').dialog('open');
			</script>
			<br />
			<a href="#" onclick="$('#dialog').dialog('close');">Close dialog</a>
		</div>
	</body>
</html>

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dolythgoeAuthor Commented:
Hey thanks for all your help!

I still can't for the life of me get it working in my script :/
0
 
Darude1234Commented:
Can you post your current script? Because the code in my example is tested and working...
0
 
dolythgoeAuthor Commented:
Hey, no worries - it worked when I wrapped the:

 $(document).ready(function() { }); around it :D

Thanks for your help!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now