Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
how to get the total for each item based on the quantity in laravel application using javascript?

I'm new to Laravel, hence unable to achive the desired result. I'm trying to get the total of each item based on their quantities provided by the user, I'm only getting the total for the first item total when quantity given but not for all items. Any help would be appreciated!

this is the image of my ordersPage

1

below is HTML code:

<p>Quantity:
  <input type="number" onchange="totalAmount()" class="item_quantity" id="item_quantity" 
    name="item_quantity">
</p>
<p>Item Price: AED - </p>
<p type="number" id="item_cost" name="item_cost" class="mb-15">
   {{ $lnkditem->item_cost}}
</p>
<p>Total Amount: AED - <strong style="color: red"></strong>
  <strong> <span style="color: red" id="total"></span></strong>
</p>

below is JS code:

 function totalAmount(){
    var quantity = Number(document.getElementById('item_quantity').value);
    var itemCost = Number(document.getElementById('item_cost').innerHTML);
    var total = quantity * itemCost;
    document.getElementById('total').innerHTML = total;
    console.log(quantity);
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That's because your using ID to set the total value. You should use classes to do that. Set the class of total span to 'total' Import jquery and do that in this way: First step : remove id's and just use class instead of id; Step 2:insert this part of code in the script part of your page:

$(document).on('change','.item_quantity',function(e){
var quantity = $(this)
var itemcost = quantity.parent().next().next():
var total = parseFloat(itemcost.html()) * quantity.val();
var total_element = itemcost.next().children('.total');
total_element.html(total);
 });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!