Nithesh Narayanan
Nithesh Narayanan

Reputation: 11775

Form Submit on Click of button in jquery model popup

In my MVC3 (Razor) application i have a page which contains a form.

 @using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
   { }

Like above. In the same page i have Jquery model popup and it contains a button. I want to submit the form form1 on the button click in the popup.

i tried

    $("#ReceiptSave").click(function (e) {
        e.preventDefault();
        $('#ConfirmationDiv').dialog('close');// for closing popup
        $("#form1").submit();
    });

But it does not works. If anybody know the reason please help me. am stuck on this.

In error console it shows the following error enter image description here

Upvotes: 0

Views: 7988

Answers (2)

Rupesh KC
Rupesh KC

Reputation: 61

@using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
{ 
    <p>main page form </p>
    <input type="button" id="ShowConfirmDiv" value="Submit" />
}

<div id="ConfirmationDiv">
    <p>Are you sure you want to submit this form?</p>
    <input type="button" id="ReceiptSave" value="Ok"/>
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $("#ConfirmationDiv").dialog({
            autoOpen: false,
        });

        $("#ShowConfirmDiv").click(function () {
            $("#ConfirmationDiv").dialog("open");
        });

        $("#ReceiptSave").click(function (e) {
            e.preventDefault();
            $('#ConfirmationDiv').dialog('close'); // for closing popup
            $("#form1").submit();
        });
    });
</script>

enter image description here

enter image description here

Upvotes: 1

karaxuna
karaxuna

Reputation: 26940

@using (Html.BeginForm("SaveReceipt", "ClinicInvoiceReceipt", FormMethod.Post, new { id = "form1" }))
{ 
    <input type="image" id="ReceiptSave" src="..." />
}

Upvotes: 1

Related Questions