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

Question: JQuery UI Diaolg on Button Click

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 (http://jqueryui.com/demos/dialog/#modal-confirmation).  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.
0
hb69
Asked:
hb69
  • 3
1 Solution
 
alien109Commented:
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() {
    $("#dialogContent).dialog();
    return false;
}
</script>

<div id="dialogContent" style="display:none;">Hi there</div>
<form id="test" onsubmit="return openDialog();">
....
</form>
0
 
hb69Author Commented:
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.

Thanks!
0
 
hb69Author Commented:
Very good, except for the IE Bug that makes it impossible to implement your suggestion.
0
 
hb69Author Commented:
UPDATE:

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

Featured Post

Technology Partners: 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!

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