javascript - Use arrays to add up values based on the title or the alt attribute -
calculating form has options , based on client enters determines products load in sidebar. products given quantity directly reflects value of option.
so per product there total price, total duration , total number of dives seen here.
num1=number(document.getelementbyid('product_quantity_' + productid).value); num2=number(document.getelementbyid('product_price_' + productid).value); nums=num1*num2; document.getelementbyid('product_price_total_' + productid).value = nums; num1=number(document.getelementbyid('product_quantity_' + productid).value); num2=number(document.getelementbyid('product_duration_' + productid).value); nums=num1*num2; document.getelementbyid('product_duration_total_' + productid).value = nums; num1=number(document.getelementbyid('product_quantity_' + productid).value); num2=number(document.getelementbyid('product_dives_' + productid).value); nums=num1*num2; document.getelementbyid('product_dives_total_' + productid).value = nums; num1=number(document.getelementbyid('product_quantity_' + productid).value); num2=number(document.getelementbyid('product_hire_' + productid).value); nums=num1*num2; document.getelementbyid('product_hire_total_' + productid).value = nums;
so need script gives grand total price of of -- 'product_price_total_' + productid).value -- , grand total duration, , third grand total dives etc.. etc...
not sure how few ideas array added fields specific alt tag or title tag.
anyone got ideas.
thanks
how this? (using same $() function Šime vidas above)
var productids = {}; function product_totals(id) { productids[id] = true; // store id's totals calculated .... } function totaltotals() { var totalpricetotal = 0; var totaldurationtotal = 0; var totaldivestotal = 0; var totalhiretotal = 0; (var id in productids) { // multiply 1 make sure it's number totalpricetotal += $('product_price_total_' + id).value*1; totaldurationtotal += $('product_duration_total_' + id).value*1; totaldivestotal += $('product_dives_total_' + id).value*1; totalhiretotal += $('product_hire_total_' + id).value*1; } }
Comments
Post a Comment