文本框值在其他文本框中分割相等

时间:2013-11-20 04:06:07

标签: javascript jquery html

第二个第三个和第四个框的值固定为100 50 50,如果用户输入300,则应将其分成100 50 50,其余100应该在余额框中...

假设如果用户输入100,则应填写第一个框,其他框应为零..

假设如果用户输入50,则应填写第二个框,其他框应为零..就像我试过以下代码但是它有错误...

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
window.update = function() {
var one = document.getElementById('one'),
  two = document.getElementById('two');    
  three = document.getElementById('three');    
  four = document.getElementById('four');   
  five = document.getElementById('five'); 



two.value = parseInt(one.value) - 100;

//if(two.value < 100)
// {
three.value = parseInt(two.value) - 50;
//}

//if(two.value > 100)
//{
 // three.value = parseInt(two.value) - 0;
four.value = parseInt(three.value) - 50;
//}
five.value = parseInt(three.value) - 50;
}



function checknumber(txtid) {
    var mynumbervalue = parseFloat((txtid).value); 
    if (mynumbervalue > 100) {
                txtid.value = "0";
                alert("Please try again. Values must be between 0-100...");
            }
    if (theid.value < 0) {
                txtid.value = "0";
                alert("Please try again. Values must be between 0-100 ...");
            }
        }     
 </script>
</head>
<body><br><p align="center">
Enter the amount to be paid<input id="one" type="text" onChange="update();" /><br>  
book fees<input id="two" type="text" name="txt"  onchange="checknumber(this)"/> 100<br>
uniform fees<input id="three" type="text" /> 50<br>
Bus fees<input id="four" type="text" /> 50<br>
balance fees<input id="five" type="text" /> <br>

</p>
</body>
</html>

0 个答案:

没有答案