Reputation: 14272
How do you compare a value from jQuery with a fixed number?
I thought this might work but it doesn't:
if (parseInt($("#days").value) > 7) {
alert("more than one week");
}
Upvotes: 0
Views: 6392
Reputation: 321864
As well as @redsquare 's answer to use .val()
, you should specify the radix:
if (parseInt($("#days").val(), 10) > 7) {
alert("more than one week");
}
This is because the value could have a leading 0, in which case parseInt
would interpret the value as octal.
Upvotes: 9
Reputation: 78687
if #days is an input then you need .val() instead of value
e.g.
if (parseInt($("#days").val()) > 7) {
alert("more than one week");
}
Upvotes: 4