Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

282
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda