Corey Coogan

Python, .Net, C#, ASP.NET MVC, Architecture and Design

  • Subscribe

  • Archives

  • Blog Stats

    • 71,564 hits
  • Meta

JQuery’s Dialog and Form Problems

Posted by coreycoogan on December 1, 2010

Sometimes there is a need to put certain elements within a FORM in a JQuery Dialog.  This sounds simple enough, but unfortunately when the dialog is displayed, the form elements can get lost as they get added outside the Form’s DOM.

The solution is simple, append the dialog element to the form. Here’s an example of how it’s done.

<script>
$(document).ready(function() {

		
       //define the dialog for later use
        var dlg = $('#AddressVerification').dialog(
        {
            autoOpen: false,
            closeOnEscape: false,
            modal: true,
            width: 550 
           }
        });

        //This is where we tie the dialog content to the parent form
       $("#AddressVerification").parent().appendTo($("form:first"));
		
		//other code not pertinent to this
});
</script>
<form>
<!-- form elements -->

<div id="AddressVerification" style="display: none;">
        <!-- address form elements -->
        <p>
            <button id="btnSave">Save</button>
            <button id="btnCancel">Cancel</button>
        </p>
    </div>

</form>
About these ads

2 Responses to “JQuery’s Dialog and Form Problems”

  1. Steve said

    Thanks for posting this. Saved me some time….

  2. geekforte said

    Thanks, saved me some time too!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: