0

i am having a razor code as below

        @using (Html.BeginForm("OtherUpdateRequest", "Members", FormMethod.Post,
 new { name = "form1", id = "form1", enctype = "multipart/form-data" }))
     {
    .......
<input type="button" value="Update Members" name="update" id="update" class="btn btn-success">

    }

and in script area after some validation the form is getting submitted as below

 $("#update").on('click', function () {
......
            if (error == 0)
            {
                alert(error);
                $("#errorDiv").hide();
                $("#form1").submit();
            }
});

it is alerting the value of error. SO it is getting inside the if condition but the form is not getting submitted.

If i change the input code as below it will get submitted but i need some jquery validation so the submit can only done through jquery. Please let me know anything wrong I am doing.

    <input type="Submit" value="Update Members" name="update" id="update" 
class="btn btn-success">

Also if I place Submit() above the alert statement the alert also won't work..

$("#update").on('click', function () {
    ......
                if (error == 0)
                {
                    $("#form1").submit();
                    alert(error);
                    $("#errorDiv").hide();

                }
    });
tereško
  • 58,060
  • 25
  • 98
  • 150
Sachu
  • 7,555
  • 7
  • 55
  • 94
  • where is that if condition? inside a submit hanlder? – AmmarCSE Jun 29 '15 at 02:04
  • http://stackoverflow.com/questions/3303874/jquery-form-not-submitting-with-id-submit-but-will-submit-with-a-subm – AmmarCSE Jun 29 '15 at 02:14
  • @AmmarCSE event handler also not working..the same submit() is firing in other forms..here it is getting inside if submit is not firing – Sachu Jun 29 '15 at 02:25

1 Answers1

1

Try like this

$("form#form1")[0].submit();
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80
  • but if i place .submit() as first statement in if the `alert(error);` won't show – Sachu Jun 29 '15 at 02:26
  • thanks bro..it worked..but can't understand why it is not firing in this form..the same is working with others. – Sachu Jun 29 '15 at 02:33
  • submit don't work in array. If you access by specific index you can get the exact dom and submit work on that. You can also try `$("#form1")[0].submit();` it will also work – Anik Islam Abhi Jun 29 '15 at 02:40
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/81825/discussion-between-sachu-and-anik-islam-abhi). – Sachu Jun 29 '15 at 02:43