0

Hi!
I have created a modal dialog. When I close it the page refreshes automatically but in my scenario the page should not do so.
The code I am using is:

$(document).ready(function () {
    $("#addaccount").dialog({
        height: 'auto',
        width: 'auto',
        modal: true,
        autoOpen: false
    });
    $("#addaccountlink").click(function (e) {
        $('#addaccount').dialog('open');
    });

Here I am opening a div tag inside a modal dialog. There is a form submit button. When I click the submit button the modal dialog closes and the page refreshes automatically.

Urgent help is needed.

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by soft_coder
0

Don't use the form submit. When you submit a form it causes a page refresh. If there is data in the form that you need to pass back to the server then do so in the click event for the button using ajax and then close the dialog. In your dialog settings you can specify a button to close the dialog and the click event this way:

$( "#addaccount" ).dialog({ 
    buttons: { 
         "Close": function() { 
                     /*grab the form data and make ajax call here could use
                      * $("#formId :input") to grab all inputs then in a function
                      * create an object that has the name:values of all the 
                      * elements selected as such. the :input selector grabs all
                      * text areas, input, checkboxes, and radio buttons so your 
                      * form should be covered
                      */
                     $(this).dialog("close"); 
                  } 
    }, 
    height: 'auto',
    width: 'auto',
    modal: true,
    autoOpen: false
});
0

Thank you very much. The solution given by you is perfect. But one thing I observed is that we can access the form data by using another method also.

$("#id").val()

By using this you can access any element in the page.
Thank once again for your help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.