0

how to call var total to down

I have tried to talk to do this but always failed. I want to call var total to be operated below but every time I call I can't can you help me?

<input class="largerCheckbox1" type="checkbox" data-exval="<?php echo $user->tertagih; ?>" <?php echo "name='id_history[]' value='1'"; ?> > 


<script type="text/javascript">
        $(document).ready(function(){
            $("#boxes input[type='checkbox']").click(function(){
                var total= 1;
                $("#boxes input[type='checkbox']:checked").each(function calc(){
                  //Update total
                  **total** += parseInt($(this).data("exval"),10);
                });

                $("#test_<?=$id?>").text(total);
                          
            });

        });

 $(document).ready(function(){
              $("#hhb").click(function(){
                  var three = 3;

                  var bilangan1 = **total**;
                  var bilangan2 = three;
                  var pengurangan = bilangan1 - bilangan2;
                  document.getElementById("pengurangan").innerHTML = pengurangan;
              });
            });

</script>
  • What do you mean by you "can't"? – Unmitigated Jul 16 '20 at 03:48
  • asterikasterik total asterikasterik - may I ask what this is referring to? Shouldn't it be "total" instead. – DpK Jul 16 '20 at 03:51
  • You've declared `total` inside the callback of the click listener, it's local to that function, hence it's not accessible outside of that function. – Teemu Jul 16 '20 at 03:53

0 Answers0