var tbv = document.getElementById("inputFrom");
var tbb = document.getElementById("inputTo");
var submit_check = document.getElementById("checkValues");
function blr() {
var von = tbv.value;
var bis = tbb.value;
console.log(von);
console.log(bis);
if (von >= bis || bis <= von) {
checkValues.disabled = true;
} else {
checkValues.disabled = false;
}
}
tbv.addEventListener("blur", blr);
tbb.addEventListener("blur", blr);
From: <br>
<input type="text" class="form-control" pattern="(|-)?[0-9]{0,3}?" title="Min: -100" id="inputFrom" />
<br> To: <br>
<input type="number" class="form-control" pattern="(|-)?[0-9]{0,3}?" title="Max: 300" id="inputTo" />
<br>
<button type="submit" class="btn btn-primary" id="checkValues"> Check </button>
As I explained above, I want to check if the value of the input "From" is greater or equal to the input "To".
The thing is, this works only by checking digit for digit, so that if input "From" has the value 12 and input "To" has the value 1, it is correct.
Anyone an idea what I´m doing wrong?
<input>value is a String, which means the values are being compared lexically, rather than numerically; you need to first convert to a Number to compare values as numbers:parseInt(von, 10),parseFloat(von),+von,Number(von)(and probably many other ways).console.log(typeof von)