javascript - java script checks two input values only by digit -
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 explained above, want check if value of input "from" greater or equal input "to".
the thing is, works checking digit digit, if input "from" has value 12 , input "to" has value 1, correct.
anyone idea i´m doing wrong?
by default .value
returns string, use parseint()
parse value number.
note: von >= bis
, bis <= von
means same. use of 1 enough.
var tbv = document.getelementbyid("inputfrom"); var tbb = document.getelementbyid("inputto"); var submit_check = document.getelementbyid("checkvalues"); function blr() { var von = parseint(tbv.value); var bis = parseint(tbb.value); console.log(von); console.log(bis); if (von >= bis) { 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>
Comments
Post a Comment