0

I have a function to call multiple fields in Joget Workflow. But sometimes the inverse function is invoked. If (pakai) is less than the (kuota) field shown correctly that is (pakai), but if (pakai) larger than the (kuota) of result displayed still (pakai), should be called (kuota).

<script type="text/javascript">
    function calculation() {
        var kuota = $('[class^=calFiel][name=totalkuota_bbm_unformat]').val();
        var pakai = $('[class^=calFiel][name=totalpakai_bbm_unformat]').val();
        if (parseFloat(pakai) < parseFloat(kuota)) {
            $('[class^=calFiel][name=total_payable_bbm_uf]').val(pakai);
        } else {
            $('[class^=calFiel][name=total_payable_bbm_uf]').val(kuota);
        }
        $('[class^=calFiel][name=total_payable_bbm_uf]').trigger('keyup');
    }
    $(document).ready(function() {
        $('[class^=calFiel][name=totalkuota_bbm_unformat]').on('keyup', function() {
            calculation();
        });
        $('[class^=calFiel][name=totalpakai_bbm_unformat]').on('keyup', function() {
            calculation();
        });
    });
</script>
Parth Raval
  • 4,097
  • 3
  • 23
  • 36
  • 1
    did you add console.log lines to figure out why? – epascarello Dec 18 '17 at 03:33
  • Can you show me how is console.log works? cause i'm new in javascript – Febby Himawan Dec 18 '17 at 03:39
  • @FebbyHimawan Don't add `console.log`. Use the debugger to properly debug your program. – Derek 朕會功夫 Dec 18 '17 at 03:42
  • `console.log(parseFloat(pakai), parseFloat(kuota), parseFloat(pakai) < parseFloat(kuota) )` – epascarello Dec 18 '17 at 03:43
  • @Derek朕會功夫 You can use console.log lines to debug..... there is no need to step through everything. – epascarello Dec 18 '17 at 03:44
  • @epascarello The debugger isn't only for stepping through the code. Using `console.log` everywhere will only cluster up your code. In fact, the debugger supports evaluating arbitrary expressions so you don't need to use `console.log` at all - the function is for logging values, not for debugging programs. – Derek 朕會功夫 Dec 18 '17 at 03:45
  • 1
    LOL, you add a console line and than you remove it. It is not like you leave it there until the end of eternity. I am guessing you were not programming before you could use debugger when all you have was document.write and alert(). A simple console.log line is all that is needed here and the fact the code is running on key presses, that really is going to screw with flow when OP types. – epascarello Dec 18 '17 at 03:51
  • @epascarello where i put that code? can you show me? i'm confused – Febby Himawan Dec 18 '17 at 03:51
  • You place it before your if statement.... You than open up the console and see what the values are. – epascarello Dec 18 '17 at 03:51
  • @epascarello still not working, is there any other way? – Febby Himawan Dec 18 '17 at 03:58
  • your code seems to work just fine - https://jsfiddle.net/jaromanda/28L53oq7/ - you're not using `,` in the numbers are you? – Jaromanda X Dec 18 '17 at 04:21
  • @JaromandaX sometimes i'm using if the number is large. but i'm confused why the function still stuck in (pakai) no matter is higher or lower – Febby Himawan Dec 18 '17 at 04:41
  • define "large" ... more than 20 digits? – Jaromanda X Dec 18 '17 at 04:42
  • i think around 15 digit, but i write this code in custom html in joget workflow – Febby Himawan Dec 18 '17 at 04:59

0 Answers0