Hi everyone,

I really need your help here..  I want to calculate the total amount should be paid when user choose product1 and product2. For example, user choose 1 product1 which cost $1 and 1 product2 cost $2, so the total amount paid is $3. How should i do that using custom HTML? My code on this javascript is so bad since i am still new with java.

Really hope someone could guide me here. 

Thanks

  • No labels

6 Comments

  1. Hi Fasha,

    Please see Calculation Field.

    Thanks.

    1. Hi Hugo,

      Thanks for your reply, but right now i am still using community edition of Joget V3, so there is no calculation field like in the Enterprise edition. I hope i could upgrade my Joget edition in the future. But for the time being, is there any alternative way i can do it using custom HTML?

      Really appreciate your kind reply.

      Thanks

      1. Try this

        function calculate(){
         $("#total").val( +$("#amount1").val() + +$("#amount2").val() );}
        
        $("#amount1").blur( function(){
        calculate();
        });
        
        $("#amount2").blur( function(){
        calculate();
        });
        

        Replace #amount1, #amount2 and #total with the fields that you have.

        More reading at http://stackoverflow.com/questions/6552959/sum-of-two-input-value-by-jquery

        1. Hi Walter,

          function calculate(){
           total = $(" total_amount ").val( +$(" amount1 ").val() + +$(" amount2 ").val() );}
          
          $(" amount1 ").blur( function(){
          calculate();
          });
          
          $(" amount2 ").blur( function(){
          calculate();
          });
          //display total in text field
          $('input[name=total_amount]').val(total);
          

          I try the coding above and the reference link you give, but i still cannot display the value in text field Total Amount Pay. Do i make a mistake on the code? I really appreciate your comment, and for your info i am still a beginner in Javascript. Then the code below:

          $(" amount1 ").blur( function(){
          calculate();
          });

          I am not really understand the used of this code. Is there anything i should add at the code?

          Thanks
          Thanks

  2. Hi everyone, 

    I know this is a very straightforward calculation. But yet since it is in Java, it does give me some trouble how to do the syntax. in my logic, it should be just like below code:

    but it shows in the total paid value is Nan. And i am not sure why. maybe my syntax is not correct. hope anyone can guide me on this.

    Thanks

    total =0;
    a = +$('input[name=amount1]').val();
    b = +$('input[name=amount2]').val();
    totalA = a*2;
    totalB = b*3;
    total = totalA + totalB;
    $('input[name=total_amount]').val(total);
    
    1. Hi Fasha,

      May I suggest that you learn up on Javascript first? The code that you have there is actually Javascript and not Java.

      Cheers.