Reputation: 21
i try do disable enter in my form using jquery, but didnt work...
View:
@using (Html.BeginForm("Create", "Contrato", FormMethod.Post, new { id="formContrato"}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
.
.
.
}
Script:
<script>
$('#formContrato').keypress(function (event) {
if (event.keyCode == '13') {
event.preventDefault();
}
});
</script>
Upvotes: 0
Views: 3209
Reputation: 1038820
Try like this:
$('#formContrato').submit(function(evt) {
evt.preventDefault();
});
Also don't forget to wrap this code in a $(document).ready
if you are executing it before the actual form such as for example in the <head>
section of your HTML. If you place the script at the end it is not necessary.
Upvotes: 1