Hi,
I have a some javascript which checks that the number in the left text box is less than or equal to the number in the right box. It sometimes works, but not always. For example, it will correctly bring up an error message if I put 5 out of 4 in the boxes or 56 out of 55. But if the boxes contain a different number of digits the error message does not show. For example, 100 out of 55 does not work and 10 out of 5 does not work. It is as if the third digit is being chopped off and the code sees the numbers as 10 out of 55 and 1 out of 5.
Here is the code:
I was wondering if someone might be able to explain what I've done wrong and how to fix it. I'm baffled!
Many thanks,
Katie
I have a some javascript which checks that the number in the left text box is less than or equal to the number in the right box. It sometimes works, but not always. For example, it will correctly bring up an error message if I put 5 out of 4 in the boxes or 56 out of 55. But if the boxes contain a different number of digits the error message does not show. For example, 100 out of 55 does not work and 10 out of 5 does not work. It is as if the third digit is being chopped off and the code sees the numbers as 10 out of 55 and 1 out of 5.
Here is the code:
Code:
<html>
<head>
<script type="text/javascript" language="JavaScript">
function CheckValue(obj)
{
var value1 = document.getElementById('q'+obj+'a'+'_element');
var value2 = document.getElementById('q'+obj+'b'+'_element');
if(value1.value !='' && value2.value !='')
{
if(value1.value > value2.value)
{
alert('The value in the right field must be greater than or equal to the value in the left. Please correct your answer.');
}
}
}
</script>
</head>
<body>
How many samples?<br />
<input id="q1a_element" type="text" name="q5a" value="" onchange='CheckValue(1);'> correct samples out of
<input id="q1b_element" type="text" name="q5b" value="" onchange='CheckValue(1);'> samples reviewed
<br />
<ul></ul></label>
</body>
</html>
I was wondering if someone might be able to explain what I've done wrong and how to fix it. I'm baffled!
Many thanks,
Katie