mercredi 12 février 2020

Add two drop-down price values as total in Laravel application

I'm building a Laravel ticket booking application where I need to calculate the price of various tickets and extra tickets to get the Total but I'm unable to do so.

What happens is that when the no. of a ticket is selected from the first drop-down that value becomes total; if I select a number of tickets for the additional members from the second drop-down, then again this second value becomes final total replacing the previous total. I need to add both totals to show the final total to the customer.

  1. First drop-down is the couple ticket price
  2. Second drop-down is the price of additional member

Below is calculation from first drop-down

<select style="width: auto;"  class="form-control" name="nooftickets" onchange="calculatefare_(this.value,'',''  )" >
        <option value="">0</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        </select>

Below is the calculation from second additional member ticket drop-down

@if(!empty($ticket['priceforadditionalone']))
            <td>

            <h4 style="color:#fd4c66;" class="m-top-45">Additional Member INR   
            @if(empty($data->id))   
            @else  
            @endif</h4>                                                                                 </td>
            <td>
            <div class="single_search_field search_location m-top-30">
            <select style="width: auto;" class="form-control" name="noofaditionalticket" onchange="calculateadditionalfare(this.value,,'-additional_member')" >
            <option value="">0</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            </select>
            </div>
            </td>
        @endif

Here is the function that is created to calculate both the pricing.

function  calculatefare_(tickets,iot,ticketname){

    var previous = iot;

 var nooftickets = tickets[0];

 var price = tickets.substr(1);

document.getElementById("calculatefare").innerHTML =  '<div id ="calculatefare"><div class="checkout-table table-responsive"> 
<table id="directorist-checkout-table" class="table table-bordered">
<thead><tr>
<th colspan="2">Details</th>
<th><strong>Price</strong>
</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><h4>Ammount(INR)</h4>
</td><td>'+ price +'</td>
</tr>
<tr>
<td colspan="2">
<h4>Total Amount(INR)</h4>
</td>
<td>'+nooftickets+'x'+price+'</td>
</tr>
<tr>
<td colspan="2">
<strong>Total amount</strong>
</td>
<td class="vertical-middle">
<div id="atbdp_checkout_total_amount">'+nooftickets*price +' + Tax</div>
</td>
</tr></tbody></table><input type = "hidden" value="'+nooftickets+' x'+ticketname+'" name="nooftickets[]" > <input type = "hidden" value="'+nooftickets*price+'" name="totalpayout" >
</div>
<div class="text-right">
<input type="submit" id="atbdp_checkout_submit_btn" class="btn btn-secondary" value="Book Now">
</div>';

}


function  calculateadditionalfare(tickets,iot,ticketname){

var previous = iot;
var nooftickets = tickets[0];
var price = tickets.substr(1);

document.getElementById("calculatefare").innerHTML =  '<div id ="calculatefare">  
<div class="checkout-table table-responsive"> 
<table id="directorist-checkout-table" class="table table-bordered"><thead><tr><th colspan="2">Details</th>
<th><strong>Price</strong>
</th></tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<h4>Ammount(INR)</h4></td>
<td>'+ price +'</td>
</tr><tr><td colspan="2">
<h4>Total Amount(INR)</h4></td>
<td>'+nooftickets+'x'+price+'</td>
</tr>
<tr>
<td colspan="2"><strong>Total amount</strong>
</td>
<td class="vertical-middle">
<div id="atbdp_checkout_total_amount">'+nooftickets*price +' + Tax</div>
</td></tr>
</tbody>
</table>
<input type = "hidden" value="'+nooftickets+' x'+ticketname+'" name="nooftickets[]" > 
<input type = "hidden" value="'+nooftickets*price+'" name="totalpayout" ></div>
<div class="text-right">
<input type="submit" id="atbdp_checkout_submit_btn" class="btn btn-secondary" value="Book Now">
</div>';

}

Instead of adding the total from both the drop-downs, total only is being calculated from the last drop-down value selected.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2SQH9cn
via IFTTT

Aucun commentaire:

Enregistrer un commentaire