In each list item, run this jQuery code specific to that item

Viewed 24

I basically want to make a simple calculation that takes quantity * current price = total price for a service..

This is just to show to costumer the price.

So i have a collection list each with a hidden popup modal for information about product.

I have made it work on the first item, but need to make it work on all other items aswell.

Here i my code for the working part:

$('.form-quantity').on("keyup mouseup change", function() {
// Get the price of product
let price = $("#pris-per").text();
// Remove the last didgits, example; 1 800(,00 NOK) the last 7 is removed
let str = price.substring(0, price.length-7);
// Convert the price to a number value
let priceNumber = Number(str.replace(/[^0-9.-]+/g,""));
    let myQuantity = $('.form-quantity').val();
    let mySum = Number(priceNumber * myQuantity);
//define as Norske kroner
const priceNo = mySum;

let kronerNO = Intl.NumberFormat("nb-NO", {
    style: "currency",
    currency: "NOK",
});
//format and change the text box with
    let numberSum = $('#text-replace').text(kronerNO.format(priceNo));
}); 

And this is what i tried:

$('.popup-card').each(function() {
  $(this).find('.form-quantity').on("keyup mouseup change", function() {
// Get the price of product
let price = $(this).find("#pris-per").text();
// Remove the last didgits, example; 1 800(,00 NOK) the last 7 is removed
let str = price.substring(0, price.length-7);
// Convert the price to a number value
let priceNumber = Number(str.replace(/[^0-9.-]+/g,""));
    let myQuantity = $(this).find('.form-quantity').val();
    let mySum = Number(priceNumber * myQuantity);
//define as Norske kroner
const priceNo = mySum;

let kronerNO = Intl.NumberFormat("nb-NO", {
    style: "currency",
    currency: "NOK",
});
//format and change the text box with
    let numberSum = $(this).find('#text-replace').text(kronerNO.format(priceNo));
    });
});
0 Answers
Related