[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Returning variable to a close event on jquery modal dialog

Posted on 2011-10-18
Medium Priority
Last Modified: 2012-05-12
Hi all,

I've got the close event working to reload the page upon closing:

		var $login = $('#login')
				autoOpen: false,
				title: 'Login',
				draggable: false,
				modal: true,
				resizable: false,
				width: 420,
				height: 210,
				position: ['center',100],
				close: function(event,ui){
				// Dialog closing so reload the page ONLY if successful login
					window.setTimeout('location.reload()', 0);

Open in new window

Prob is, this will reload the page even if the user clicks the 'close window' option and doesn't login which is not needed (only when successfully logged in since this is when the session variables change).

Is there a way I can pass a variable back to this close event - so to speak? Do some checking - if (blah == true) { close } else { dont } type thing?

Question by:dolythgoe
  • 2
  • 2
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36991648
why not declare that variable globally and then check that global variable?
LVL 83

Expert Comment

ID: 36991780
why do you want to put the code inside close option?

just use the following where you're able to do the test
if(blah == true) $('#login').close();

Author Comment

ID: 36994167

The code is in the close option because the user can close the dialog at anytime, they do not need to complete it. The 'X' in the top right corner.

However, if they do complete the process in the dialog - i.e. login, then the dialog is closed automatically an reloads the page.

Perhaps I can reload the page then close the window in the else code..not sure if that will work as I thought the reload would mess with it. I'll give it a try...
LVL 83

Accepted Solution

leakim971 earned 2000 total points
ID: 36994454
put :
if(blah == true) $('#login').close();

Open in new window

anywhere you want to allow the user to close the dialog box

if you put it inside the close event, it mean you don't need it...


Author Comment

ID: 36994543
The purpose is to do the following:

- User clicks login
- Up pops the dialog
- User logins
- Sessions are registered via php ajax
- Window closes and page reloads for the session code to pick up on the registered sessions and update a few things

I want them to be able to unconditionally close the login at any point - they don't have to complete the login.

The issue is the reload page is issued on the close event which means it also reloads if they don't login.

So the issue is about reloading the page depending on how it was closed - i.e. successful login or not.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question