I have put a text box where i want only numbers. I want to validate it in the client side and written the following code
@using (Html.BeginForm("LoyaltyPoints","Cart",FormMethod.Post))
{
<label>Enter point:</label>
<br />
@Html.TextBoxFor(m => m.txtLoyaltyPoints, new { @onkeypress = "OnlyNumeric(this)" })
<br />
<input type="submit" value="Submit" />
<br />
@ViewBag.LoyaltyPointsErrorMessage
}
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
function OnlyNumeric(e) {
if ((e.which < 48 || e.which > 57)) {
if (e.which == 8 || e.which == 46 || e.which == 0) {
return true;
}
else {
return false;
}
}
}
now here my javascript is not firing. i tried keeping alert here but not working as intended. What could be the error. please help.