I try to subtract the value between two textfields, user enter one value(must be 1-100), then the result will load in the other textfield. But the problem is when the user enter more than 100, then the result will change to negative. How to solve this problem?
Many thanks
Student
<script>
function soma2(){
var wtemp=0
wresult=100
for (var k=2;k<3;k++){ // loop to get all inputs
wtemp=eval(“parseFloat(document.all.box”+k+”.value)”)
if(!isNaN(wtemp)) wresult-=wtemp // if value is a number – add it.
}
document.all.result2.value=wresult // change the last input…Result one
}
</script>
<script>
function soma3(){
var vtemp=0
vresult=100
for (var i=31;i<35;i++){ // loop to get all inputs
vtemp=eval(“parseFloat(document.all.box”+i+”.value)”)
if(!isNaN(vtemp)) vresult-=vtemp // if value is a number – add it.
}
document.all.result3.value=vresult // change the last input…Result one
}
</script>
<style type=”text/css”>
<!–
.style5 {color: #FF0000; font-style: italic; font-size: x-small; }
–>
</style>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”41%”><div align=”center”>Individual assessment</div></td>
<td width=”59%”><input name=box2 type=”text” id=”box2″ onchange=”soma2()” size=”2″>
% </td>
</tr>
<tr>
<td><div align=”center”>pair / group work assessment </div></td>
<td><input name=result2 type=”text” id=”result2″ onFocus=”this.blur()” size=”2″>
% <span class=”style5″>(The system will auto count the number)</span> </td>
</tr>
</table>