0

I've tried many times but can not figure out how to get this full script to run on click it will not work. Need answer to change after the value of the input has been changed.

<input id="a" value="500" type="number">

<p id="b"></p>

<script>
    var bills = [100, 250, 450, 950, 1150]; 
    var money = mod(document.getElementById("a").value);

    function mod(num){
        if (num % 5 === 0){
            return num;
        } else {
            return num + 5 - num % 5
        } 
    }

    function foo(num){
        var index = bills.length - 1;
        var splits = [];
        while (money >= bills[0]){
            if (money >= bills[index]){
                money -= bills[index];
               splits.push(bills[index]);
            } else {
                index--;
            }
        }
        return splits; 
    }

    document.getElementById("b").innerHTML = foo(money) </script>
j08691
  • 204,283
  • 31
  • 260
  • 272
  • 2
    I don't see any attempts to handle a click or change event in your snippet. Also, your question says *"...get this full script to run on **click**"*, and *"...after the input has been **changed**"*. Which is it? – Tyler Roper Jul 18 '17 at 13:54
  • If you don't mind using jQuery, then see here: https://stackoverflow.com/questions/1481152/how-to-detect-a-textboxs-content-has-changed – Peter B Jul 18 '17 at 14:05
  • sorry the button is missing but on click as other input and scripts will be added later but not yet i didn't include the on-click attempts as the script is fully functional in that format @Santi – Sean Reed-Forrester Jul 18 '17 at 14:05

0 Answers0