views:

39

answers:

1

I am having a problem with some jquery dialog code. The window opens ok the first time and if I submit the form, it returns the message in the div. However, if after closing the dialog, I open it again, it still retains the message and has not cleared. Also, when I press the submit button, it will open the php page twice. It seems to do this on each time I open the dialog. If I close and open the dialog again it will open the php page 3 times. Where am I going wrong with this?

    // feedback form
$(document).ready(function(){
    function feedbacknew() {

    // jquery-ui confirm dialog box 
    $("#form").dialog({
        autoOpen: false,
        resizable: false,
        modal: true,
        title: 'Submit a feedback request',
        width: 440,
        height: 470

        /*buttons: {
            'Remove': function () { // remove what you want to remove 
                // do something here 
                alert("this is a test alert!");
                $(this).dialog('close');
                $("#flex1").flexReload();
            },
            Cancel: function () {
                $(this).dialog('close');
            }
        }*/
    });
    });


    $('#submit').click(function () {
        var name = $('.uname').val();
        var data = 'uname=' + name;
        $.ajax({
            type: "POST",
            url: "feedback.php",
            data: data,
            success: function (data) {
                $('#message').html(data);
                $("#flex1").flexReload();
            },
            error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
                } 
        });
        return false;
    });

    $("#form").dialog('open');

}
A: 

Take out the "$("#form").dialog({....});" code from the feedbacknew() function place it above it (put it in the global page scope, but inside a $(document).ready(function(){}); ). You're redefining the dialog box every time that function executes.

Xinil
i have updated the code and it is giving syntax error at )}; after the commented code. because i am a new user to jquery trying to learn, could you point out my error? many thanks
Mr.Putersmit
any further help with this? thanks
Mr.Putersmit