Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Hi,
I have textboxes,one for ssc marks(0-600) and another is inter marks(0-1000)
I want to write validation for these two textboxes using jQuery.
What should I write in my Scripting??
The following code is What I wrote in my WebForm...
<script type="text/javascript">
function f1(){
var txtssc = $('[id*="txtssc"]').val();
var txtinter = $('[id*="txtinter"]').val();
if (txtssc == "") {
$('[id*="txtssc"]').notify("Marks should not be empty", { position: "top" });
$('[id*="txtssc"]').next().show();
return false;
}
if (txtinter == "") {
$('[id*="txtinter"]').notify("Inter Marks should not be empty", { position: "top" });
$('[id*="txtinter"]').next().show();
return false;
}
}
if (txtssc <=0&&txtssc>=600) {
$('[id*="txtssc"]').notify("Please enter valid SSC Marks ", { position: "top" });
$('[id*="txtssc"]').next().show();
return false;
}
if (txtinter <=0&&txtinter>=1000) {
$('[id*="txtssc"]').notify("Please enter valid Inter marks, { position: "top" });
$('[id*="txtssc"]').next().show();
return false;
}
<script/>
So,my problem is I should not enter less than 0 and greater than 600 and the warning message should display..
Please help me in this code..
Posted

1 solution

This is how:
JavaScript
var value = parseInt(txtssc);
if (value) {
   if (value < 0 || value > 600)
      showThatValueIsNotInRange(value);
} else // value could be NaN, then:
   showThatStringHasInvalidNumericFormat(txtssc);

Write those show* functions the way you want. Please see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900