hi im new to jquery and im facing these problem
i have these code
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(".adults").change(function(){
var test = $(".maxpeople").val();
if ($(this).val() > $(".maxpeople").val()) {
alert("test");
}
alert(test)
});
</script>
and i need to compare the digits and if the value of .adults is bigger than the value of .maxpeople then show me an alert.
the code works but it looks like it only takes one digit.
exjample:
.maxpeople = 17
i put 1 in .adults and is ok but if i put 2 it shows the alert, now if i put 16 it doesnt show the alert.. what im i doing wrong??
val()is going to return a string. If you want to compare numbers, you will have to convert the strings to numbers.Assuming you just want integers, use
parseInt.