I am reading a value as
var result = $("#Time", $(this)).val();
If I enter “Hours” instead of a number , and I do 0<parseInt(result, 10)<24), the result is true when I expect it to be false.
What is wrong with my code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your first comparison
0 < NaNwill yieldfalse, which is sort of 0, therefore0 < 24, which is true.I also note that you seem to be passing context incorrectly. The context parameter to jQuery should be a DOM node, not a jQuery object, so use
$('#Time', this). Note that there’s no use for that parameter in this code as accessing by ID is really quick as it is, and because you aren’t using theTimeid for more than one element in the document, right? Well you shouldn’t.