Fruitbeard i think you can help me with this. I'm having problems with my additions and substraction.


PHP Code:

var cantidad=250;     //amout of  money in the wallet
var saco=0;             //money deposited on the soda machine

if(money.text!=""){       //if the input textbox is NOT empty, then do the script below
    

    
if(pressed==false){
    
    
pressed=true;
    
        if(
cantidad<50){       //if  the amount of money left in the wallet is below 50 cents
    
    //do nothing
}

    
//if not, if the value shown in the input textbox (money.text) and in the monitor textbox (saco) is lower than 50
    
else if(saco<50 && money.text<50){
    
      
//then show in the monitor textbox (saco) the value typed in the input textbox (money.text)
    
saco += parseFloat(money.text)
    
//increase or substract the value shown on the monitor textbox (saco), in other words, if you typed 50 on the input textbox, it will substract 50 of the cantidad amount.
        
cantidad -=saco
    
//empty the input textbox
money.text=""
    
    
}
//if the monitor textbox and the input textbox is higher than 50
    
if(saco>50 && money.text>50){

//show 50     , the soda machine only supports .50 cents at once    
saco=50;
    }
    

trace("Pressed");
    
trace("Unpressed");
    }
    } 
It works if i type 50 , or I deposit 50 from 10 to 10 (10+10+10+10+10) but if i type 10, then 60, it shows 60, and the machine only supports 50 cents, so it will substract 60 to the money in the wallet.

It's like a buying system, you have $2.50 in the wallet, and the soda cost $.50 cents, but i want the people enter any amount of money on the input textbox, but the monitor textbox only will retain 50 (.50 cents to buy the soda) and the rest will be stay on the wallet. Then when you click on the soda button, everything will reset to 0 but the cantidad variable that is the amount of money left in the wallet. Thanks