I have a cart page where the quantity is not the correct quantity as the products are sold in bulk (1, 10, 100 items).
What I am trying to achieve is getting the number of items in the pack, multiply by the quantity and display the total number of items.
Here's a JSFiddle and the code:
jQuery(document).ready(function($){
$( ".variant_title" ).each(function() {
var str = $(this).text();
var qty = $(this).nextUntil('input[id^=updates_]').val();
console.log(qty);
if ( str.indexOf('jackets') > -1 ) {
unities = str.slice(18,21);
if (unities === '100' || unities === '10 ') {
console.log(unities);
totalUnities = unities * qty;
console.log(totalUnities);
$(this).append('<br />' + totalUnities + ' Unities');
}
} else {
unities = str.slice(18,19);
if (unities === '1') {
console.log(unities);
totalUnities = unities * qty;
$(this).append('<br />' + totalUnities + ' Unity');
}
}
});
});
Table example
My problem now is traversing the DOM and getting the value of the input field next to the description and multiplying.
Does anyone know where am I making a mistake here?
Thanks
var str = $(this).text();
var tr = $(this).closest('tr');
var qty = $(tr).find('input').val();
console.log(qty);
Yo need to get your parent element (tr here) and find the input to get your quantity. hope this help
nextUntil(-selector-) method selects all prior elements to -selector-
use this approach to get quantity:
var str = $(this).text();
var qty = $(this).parents('.item').next('td.qty').find("input[id^='updates_']").val();
http://jsfiddle.net/eetyr6ae/3/
How to prevent a token created with OAuth 2.0 from expiring?
I'm using masonry layout for my website and I'm generating the boxes from php. whenever i have a lot of text on one of the p tags or the box, the text overflows out of the tag.
I am generating a table using jQuery and loading its rows from a data structure. .
I am using PhantomJS 2 and the latest CasperJS to test a remote webpage containing some TypeErrors. While logging into the webapp, a popup.