How can i dynamically change values for my paragraphs depending on the product selected?
In my code this is what is happening. When i select MacBook and enter the qty, i am able the actual total price but after i select another product, it globally changes the Total for every product already selected.
Item: MacBook
Amount : 8900
Qty : 1
Total : 1200
Item : HP Probook
Amount : 1200
Quantity: 1
Total: 1200
JS
function OptionsSelected(product)
{
$('.container').append(
'<div class="product">'+
'<input type="hidden" value='+product.id+' name="product[] />'+
'<p class="name"> Item: ' + product.name + '</p>'+
'<p class="price" data-price="'+product.value+'">Price : ' + product.value + '</p>'+
'<input type="text" class="quantity" name="quantity" />'+
'<p class="total">Total $:<span></span></p>'+
'</div>'
).appendTo('form')
$('.container').on('keyup','.quantity',function()
{
var a = Number($(this).val());
var b = Number($(this).closest('div').find('.price').data('price'));
c = a * b;
//debugger --breakpoint
alert('Debugging prices for items selected ' +b);
$(".total span").text(c);
});
HTML
<input onclick="return OptionsSelected(this)" type="checkbox" id="{!! $product->id !!}" name="{!! $product->name !!}" value="{!! $product->price !!}" />
<div class="container" id="container">
</div>
PS:I tried to create a working snippet but i couldn't get that working and this is a new thread for a question already asked
OptionsSelectedadds a newkeyupevent listener to#containervalue='+product.id+' name="product[] />'3. There's no code related to .total in your question