Introduction: In
this article today I will explain how we can validate the minimum and maximum
price using Jquery
Description:
In the previous article I have explained Show Gridview row detail in Tooltip on mousehover using Jquery in asp.net;Validate Listbox using Require filed validator control in asp.net,Server side validation in MVC Razor using data annotation,Like linq query example and bind gridview,Create a dynamic Slider in asp.net, URL routing in asp.net website and Validate Dropdownlist using Require filed validator control in asp.net.
Add a webform to project and design the page as given below:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Validation For Minimum and maximum Price</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<fieldset style="width:45%;height:50px">
<legend>Validation For Minimum and maximum Price:</legend>
Minimum price:<asp:TextBox ID="minprice" runat="server"></asp:TextBox>
Maximum price : <asp:TextBox ID="maxprice" runat="server"></asp:TextBox>
</fieldset>
</center>
</div>
</form>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
<script>
$("#minprice, #maxprice").change(function (e) {
var lil = parseInt($("#minprice").val(),
10);
var big = parseInt($("#maxprice").val(),
10);
if (lil > big) {
var targ = $(e.target);
if (targ.is("#maxprice"))
{
alert("Maximum price must be greater
than Minimum price");
$('#maxprice').val(lil);
}
if (targ.is("#minprice"))
{
alert("Minimum price must be less than
Maximum price");
$('#minprice').val(big);
}
}
});
</script>
</body>
</html>
Run the project and check
Is this article helpful for you?
No comments:
Post a Comment