How can I implement Enter key press functionality to login to the system using JavaScript? Below is the code snippet:
@using (Html.BeginForm("Login", "InventoryBarcode", FormMethod.Post, new { id = "main" }))
{
<label for="LoginName" class="uname">Account</label>
<input type="text" name="LoginName" id="LoginName" value="" placeholder="Please Enter Account" />
<label for="LoginPassword" class="youpasswd">Password</label>
<input type="password" name="LoginPassword" id="LoginPassword" value="" placeholder="Please Enter Password" />
<asp:TextBox ID="txtLoginPassword" runat="server" TextMode="Password" placeholder="Please Enter Password"></asp:TextBox>
<span id="message" style="color:red">@ViewBag.Message</span>
<input type="button" name="Login" id="Login" value="login" onclick="Check();" />
}
<script src="~/Scripts/jquery-3.1.1.js"></script>
<script type="text/javascript">
function Check() {
if ($.trim($("#LoginName").val()) === "") {
$("#message").text('Please Enter Account!');
return false;
}
if ($.trim($("#LoginPassword").val()) === "") {
$("#message").text('Please Enter Password!');
return false;
}
$("#Login").hide();
$("#message").text('Login Please Wait...');
$("#main").submit();
}
$(document).keypress(function(event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
Check();
}
});
</script>