dimanche 23 avril 2023

How can I use the variable from php class FinalPrice to javascript class?

I have this function in this location Main/resources/views/dashboards/solicitor/managewills/solicitorclass.php

 var counts = 1;
 var checkboxes;
function add_to_download_entries(data) {
   checkboxes = document.querySelectorAll('input[name="checkWills"]:checked');
    counts = checkboxes.length;
  if($.inArray(data, selected_lostwill_array) >= 0){
    selected_lostwill_array = $.grep(selected_lostwill_array, function(value){
         return value != data;
       });
     }else{
      selected_lostwill_array.push(data);
     }
     // DataTables Functions 
$(document).ready( function () {
    $('#org_lost_table').DataTable();
    $('#all_lost_table').DataTable();
    if(counts>0){
        let finalPrice = "Pay Now $" + Number(counts) * Number(22);
        
        $( "#payment-sub-btn" ).text(finalPrice);
       }else $( "#payment-sub-btn" ).text(0); 
} );
}

I want to use the finalPrice variable value when it updates there to this class at the places where I have let payPrice = 44 - ((44*results['data'])/100); in the place of 44 in location `Main/public_html/js/payment/payment_report.js

function checkCoupon() {
count++;
    var coupon = document.getElementById('lost_coupon').value;
    $.ajax({
        type: "POST",
        url: app_url+"/check_coupon_report",
        data: {
            "_token": csrf_token,
            "coupon": coupon,
        },
        dataType: "json",
        success: function(results) {
        
            if (results['status'] == true  && results['used'] == false) {
                $("#couponMessage").text("Congratulations Your coupon is valid. ");    
                $("#couponMessage").css("color", "green");   
                $("#couponMessage").css("visibility", "visible");   
                let payPrice = 44 - ((44*results['data'])/100);
                $("#couponMessage").append('Your discount is ' +results['data']+'%.' + '<br>Your final price is $' + parseFloat(payPrice.toFixed(2)));
                finalPrice  = parseFloat(payPrice.toFixed(2)) * count;
                $('#payment-sub-btn').text('Pay Now $'+finalPrice);
                console.log(finalPrice);
                if(results['data'] == 100) {
                    $('.card-element-hide').hide();
                    card.destroy();
                    card = null;
                    $('#payment-sub-btn').text('Download Report');
                }
                else{
                $('.card-element-hide').show();
                if(card == null) {
                    createCard();
                    }
            }
            }
        

How can I use the variable from php class FinalPrice to javascript class?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire