ho questa funzione javascript per convalidare se un numero è maggiore di un altro numerojavascript se il numero maggiore di numero
function validateForm() {
var x = document.forms["frmOrder"]["txtTotal"].value;
var y = document.forms["frmOrder"]["totalpoints"].value;
if (x > y) {
alert("Sorry, you don't have enough points");
return false;
}
}
Non funziona per qualche ragione.
Se faccio alert(x)
ricevo 1300, e alert(y)
dà 999
Questo funziona ....
function validateForm() {
var x = 1300;
var y = 999;
if (x > y) {
alert("Sorry, you don't have enough points");
return false;
}
}
Si stanno confrontando stringhe, non numeri. –
@ user1689607 Il confronto delle stringhe numeriche continuerà a funzionare, vale a dire "5"> "2" // true' –
@MattStone: '" 1300 ">" 999 "; // false' –