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");
}
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");
}
if #days is an input then you need .val() instead of value
e.g.
if (parseInt($("#days").val()) > 7) {
alert("more than one week");
}
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.