user2378411
user2378411

Reputation: 35

Issues with dialog box

I have a dialog box that needs to show when a user clicks on submit. The user then has to either accept the terms of the usage of our resources.

<script>

$(document).ready(function() {
        $(function() {
            var Form;
            $("#confirm").dialog({
                height: 200,
                width: 200,
                modal: true,
                buttons: {
                    'No': function() { // No works (since I only need to close the box)
                        $(this).dialog("close");
                    },
                    'Yes': function() { // This is not working. The button just keeps me on the same page with no submission
                        Form.submit();
                    }
                }
            });
        });

    $("#acceptform").submit(function() { // This is the form that a user has to submit before the dialog box appears
        Form = this;
        $('#confirm').dialog('open');
        return false;
    });
});

</script>

If there are any other things need to better ask this question please let me know.

Upvotes: 2

Views: 79

Answers (1)

rahul maindargi
rahul maindargi

Reputation: 5655

Key to solution is identify if Confirm box already Open... if its already open then Form is being submitted then form need to continue...

In yur case when you do form.submit .. the code agaiin goes to submit handler and returns false... so form submition fails. DEMO

$(document).ready(function() {
        var FORM=$("#acceptform");
        $(function() {
            $("#confirm").dialog({
                height: 200,
                width: 200,
                modal: true,
                buttons: {
                    'No': function() { // No works (since I only need to close the box)
                        $(this).dialog("close");
                        FORM.data("confirmProgress",false);
                    },
                    'Yes': function() { // This is not working. The button just keeps me on the same page with no submission
                        FORM.submit();
                        FORM.data("confirmProgress",false);
                    }
                }
            });
        });

    FORM.submit(function() { // This is the form that a user has to submit before the dialog box appears

        if(!$(this).data("confirmProgress")){

            $(this).data("confirmProgress",true);
            $('#confirm').dialog('open');
            return false;
        }else{
           return true;
        }
    });
});

</script>

Upvotes: 1

Related Questions