Click here to Skip to main content
14,935,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi frnds
Below code works fine is there any possibility to use same code with loops plz help...

HTML
<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');
    six = document.getElementById('six');

    //checking if value is less than 100
    if(one.value < 50) {
        two.value = 0;
        three.value = 0;
        four.value = 0;
    five.value = 0;
        six.value = one.value;  
    }
    else if(one.value == 50) {
        two.value = 0;
        three.value = 50;   
        four.value = 0;
  		five.value = 0;
        six.value = 0;
    }
    else if (one.value < 100) {
        two.value = 0;
        three.value = 50;    
        four.value = 0;
		five.value = 0;
        six.value = parseInt(one.value) - three.value;     
    } else if (one.value == 100) {
        two.value = one.value;    
        three.value = 0;
        four.value = 0;
		five.value = 0;
        six.value = 0;
    } else if (one.value > 100)
	{
        two.value = 100;
        if ((one.value - two.value) >= 50) 
		{
            three.value = 50;
            if ((one.value - two.value - three.value) >= 50) four.value = 50; 
        else 
			four.value = 0;
			            if ((one.value - two.value - three.value - four.value) 
    >= 60) five.value = 60;
						else
						five.value = 0;

            six.value = one.value - two.value - three.value - four.value - five.value;
        } 
		else 
		{
            three.value = 0;
            four.value = 0;
			five.value = 0;
            six.value = one.value - two.value - three.value - four.value - five.value;
        }
    }
    }
    </script>
  <br>
    <p align="center">Enter the amount to be paid
    <input id="one" type="text" onchange="update();" onkeypress="update()" />
    <br>fees1
    <input id="two" type="text" name="txt" onchange="checknumber(this)" />100
    <br>fees2
    <input id="three" type="text" />50
    <br>fees3
    <input id="four" type="text" />50
    <br>fees4
    <input id="five" type="text" />60
    <br>balance fees
    <input id="six" type="text" />
    <br></br></br></br></br></br></br></p></br>
Posted
Updated 21-Nov-13 18:19pm
v2
Comments
   
Any questions?
—SA
Arun-23 22-Nov-13 0:07am
   
is there any possibility to use same code in loops like for while etc..
Thanks7872 22-Nov-13 0:22am
   
This is not a question. Implement it and then post the difficulty you face.
Arun-23 22-Nov-13 0:28am
   
why i want to use this code in loop because i had tried same code with onkeypress event it updates the give value but if i press 1 its doents shows in balance box if i press another number for ex same another 1 it shows 1 in balance box.. it need to show before another key is pressed is there any solution..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900