Question: JQuery UI Diaolg on Button Click

Posted on 2009-05-11
Last Modified: 2013-11-05
Does anyone know how to get any variant of the JQuery UI Modal Dialog to pop up and stay popped up when the user clicks a button?

I got the default example working great on my local machine (  The default example pops up on docready.  No problem.  Then I wanted it to only pop up when the user clicks "submit" on a form.  I thought this would take seven seconds, and seven hours later I'm out of options.

No code sample provided. ANY pointing in the right direction or any sample will be greatly appreciated.  BTW - I can get the modal dialog to pupup on the click event, but it disappears in a split second because of postback / form submit.  I'd think the modal: true would stop form submit in the same way that alert('hello world'); will totally stop a form submit but ... nope it doesn't.

Anyone?  Thanks in advance.
Question by:hb69
  • 3
LVL 12

Accepted Solution

alien109 earned 500 total points
ID: 24358865
shouldn't be too tough...

add an onsubmit event handler to the form (that returns false!) then in that handler function get the node that holds the content you want displayed and execute the dialog method.

something like:
<script type="text/javascript">
function openDialog() {
    return false;

<div id="dialogContent" style="display:none;">Hi there</div>
<form id="test" onsubmit="return openDialog();">

Author Comment

ID: 24364383
Here's the deal.  I'm going to give you the points because what you suggested worked in non IE browsers.  That it totally crashes Internet Explorer is not your fault and not a fault of your solution.  But, none the less I cannot do what you suggested because of a well known IE issue.  I'm using .net BTW.

If you are aware of how to work around the IE Bug (freezes the screen so hard that you can't even close IE except through the task manager and even then doesn't shut down gracefully) you or somebody else should post that as a separate solution.


Author Closing Comment

ID: 31580319
Very good, except for the IE Bug that makes it impossible to implement your suggestion.

Author Comment

ID: 24366110

I used a workaround and rescued my pretty dialog box from oblivion.  What I did was I created two panels on my form.  During initial login we show one panel.  That panel does not contain the <div> for the UI Dialog, and it does not contain the JS.  IF upon postback the conditions exist for the dialog to display, I then set the first panel to visible=false, and visible = true to the other panel which contains the dialog box and it's JS.  It pops up and asks it's questions.

Apparently, IE is totally OK with this solution.  It does not affect how the javascript is written, but does affect when it can be placed on the page.  I don't know if this is the best solution or even a good solution but it works and I'm moving forward with it.

Adding the attribute to the form itself (onSubmit do this)  so that a validate javascript halts the execution of code seems to not work well in .net/IE.  So my advice for those who read this is if you are using .net, then place your dialog in panels and show the panel with the dialog as needed, and place all dialog code (html and js) inside of that panel.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

by Julian Matz As of jQuery ( 1.4 the .live() method ( supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
The viewer will learn how to dynamically set the form action using jQuery.
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)

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now