rabal rabal - 5 months ago 8
HTML Question

The value of second input type="number" cannot be exceed to the value of the first input type="number" maxlength="3"

I hope someone can help me on this. Thank you so much in advance.

this is the testing code.

<html>
<body>

<input id="first" name="first" type="number" maxlength = "3" >

<input id="second" name="second" type="number" maxlength = "3" >

</body>
</html>

Answer

If I am understanding correctly, you are not getting any errors but you are looking to do a comparison on two inputs.

You are going to have to use javascript. You will need to store each input in a variable. Then you will need to write a function to compare the values of these variables and display an output.

For example:

<button type="button" onclick="compare()">Compare!</button>

<script>

function compare()
{
 var firstNumber = document.getElementById("first").value;
 var secondNumber = document.getElementById("second").value;
 if(firstNumber == secondNumber)
 {
  alert("The numbers are equal");
 }
 else if(firstNumber > secondNumber)
 {
  alert("The first number is larger");
 }
 else
 {
  alert("The second number is larger");
 }
}

</script>

Then you would put your own code in where the second number is larger based on what you want to happen.

Edit: Sorry if you wanted this in classic ASP. I'm sure you'll be able to translate it into it anyway.

Comments