Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
HTML
<script>
     function getMoney() {
        var i = parseInt(document.getElementById("money").value)

        if (i == null || i == "") {
            alert("Please!! Input Money")
            document.getElementById("money").focus();
            return false;
        } else if (i % 100 == 0 && i<=144000 ) {
            getData();
        } else if (i % 100 && i<=144000) {
            alert("Please!! Input Money again...")
            document.getElementById("money").focus();
            return false;
        } else {
           alert("Error !! Input money again...")
    }
}

function getData(){
var totalThousand = 99;
var totalFivehundred = 30;
var totalHundred = 300;


 var a,b,c;
 var remain, money;

 remain = money, a = b = c = 0;
 money = parseInt(document.getElementById("money").value)

 aa      = money / 1000;
 var a = aa.toString();
 var thousand = a.split(".");
 remain = money % 1000;

 bb      = remain / 500;
 var b = bb.toString();
 var fivehundred = b.split(".");
 remain = remain % 500;

 cc      = remain / 100;
  var c = cc.toString();
 var hundred = c.split(".");
 remain = remain % 100;

 var aaa = parseInt(thousand[0]);
 document.getElementById("panTotal").innerHTML = totalThousand - aaa ;


  var bbb = parseInt(fivehundred[0]);
 document.getElementById("fifTotal").innerHTML = totalFivehundred - bbb ;

  var ccc = parseInt(hundred[0]);
 document.getElementById("oneTotal").innerHTML = totalHundred - ccc ;

document.getElementById("pan").innerHTML = thousand[0];
 document.getElementById("fif").innerHTML = fivehundred[0];
 document.getElementById("one").innerHTML = hundred[0];
document.getElementById("balance").innerHTML = money;

}

 function reset() {
    document.getElementById("information").reset();

    $.get( "js/json.js", function( data){
  JSONItems = JSON.parse(data);
  console.log(JSONItems);
});
}
</script>


What I have tried:

Quote:
I have tried to fix else if condition but it's not work.
when you enter input more than 144000 it's not show an error message. Thank you for your kind support.


First problem has fix, I have found another problem when input 144000 ฿.
It will show like "Amount of banknotes
1000 banknote : -45
500 banknote : 30
100 banknote : 300"

How can I fix it, I want it to show "Amount of banknotes
1000 banknote : 0
500 banknote : 0
100 banknote : 0"

Sorry for asking too many question.
Posted
Updated 17-Mar-17 10:11am
v8
Comments
CHill60 17-Mar-17 11:05am    
You've posted this question twice - delete one of them
Member 13064822 17-Mar-17 11:09am    
oh okayy
SrikantSahu 17-Mar-17 11:21am    
Just tried your code by entering 144001 and its showing the error in the alert. What is the issue here?
F-ES Sitecore 17-Mar-17 11:22am    
Check the error console for messages and use the "debugger;" keyword to step through your js to see what is happening.
ZurdoDev 17-Mar-17 11:22am    
1. Please do not post so much extra code for us to have to look through. None of the CSS or html is important to your question, right?
2. Just debug your code. Put a breakpoint in and see what is happening. You'll fix it very fast that way.

1 solution

Quote:
It will show like "Amount of banknotes
1000 banknote : -45
500 banknote : 30
100 banknote : 300"

How can I fix it, I want it to show "Amount of banknotes
1000 banknote : 0
500 banknote : 0
100 banknote : 0"

Your problem is that when you calculate the number of banknotes you need, you forget to check that you have enough of each kind.

As already adviced, use the debugger to see what your code is doing.
 
Share this answer
 

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