Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  54] [ 1]  / answers: 1 / hits: 31370  / 13 Years ago, sat, november 12, 2011, 12:00:00

So I'm just testing something with js, basically the number in the first input has to be bigger than the number in the second input for the submit button to be activated.



The button get's disabled just right, but if I change the number it won't activate again



<!DOCTYPE HTML>
<html>
<body>
<input type='number' id='first' onchange=validateNumber()/><br>
<input type='number' id='second' onchange=validateNumber()/><br>
<script type=text/javascript >
function validateNumber()
{
var first = document.getElementById('first').value;
var second = document.getElementById('second').value;

if(first > second){
document.getElementById('sub').disabled=false;
}else{
document.getElementById('sub').disabled=true;
}


}
</script>
<input type=submit id=sub/>
</body>
</html>


Edit:
The arrows of the number input trigger onchange it seems, that caused the problem


More From » html

 Answers
7

You have to add the onclick and onkeyup event in order to respond to mouse interactions and to inserts from the clipboard:



http://jsfiddle.net/wzvvN/1



<input type='number' id='first' onkeyup=validateNumber() onclick=validateNumber() onchange=validateNumber() />

<input type='number' id='second' onkeyup=validateNumber() onclick=validateNumber() onchange=validateNumber() />

[#89163] Friday, November 11, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yaquelina

Total Points: 517
Total Questions: 101
Total Answers: 96

Location: Egypt
Member since Tue, Jul 6, 2021
3 Years ago
yaquelina questions
;