Your
checkPrice
function needs to return
true
if the validation passes.
The two local variables will be
string
s; the
string
type does not have a property called
val
.
I'm guessing you want to compare the values as numbers, not as strings. If you compare them as strings, then
"2"
is greater than
"10"
.
function checkPrice(){
var lastprice = parseFloat(document.getElementById('lastprice').value);
var harga = parseFloat(document.getElementById('harga').value);
if (isNaN(lastprice) || isNaN(harga)) {
alert("Entered values are not numeric.");
return false;
}
if (harga > lastprice) {
alert("Entered value is bigger");
return false;
}
return true;
}