jQuery(document).ready(function($) {
var price = 0;
var documents = "Documents (Up to 1kg)";
var small = "Small (1-5kg 85cm)";
var medium = "Medium (5-10kg 110cm)";
function checkTotal() {
var qty = $("input[name*='qty']");
var piece_type = $("select[name*='piece_type']");
var total = 0;
var row = $(this).closest('tr');
qty.each(function(index) {
var spanID = $(this).closest('tr').find('span[name="wpc_subtotal"]');
var sum = 0;
var quantity = $(this).val() ? $(this).val() : 0;
var selected = piece_type.eq(index).find(":selected").text();
if (selected == documents) {
price = 10;
sum = parseFloat(quantity) * parseFloat(price);
}
if (selected == small) {
price = 20;
sum = parseFloat(quantity) * parseFloat(price);
}
if (selected == medium) {
price = 30;
sum = parseFloat(quantity) * parseFloat(price);
}
total += sum;
spanID.text("Subtotal : " + sum);
});
$("#wpc_total").text("Total : $" + total);
//$("[name*='wpc_subtotal']").text("Total : $" + total);
}
function delete_row() {
//gets current dropdown value
//alert(service_type);
var service_type = $("#service_type option:selected").text();
//Use the current element to context to target parent <TR>
var tr = $(this).closest('tr');
//Use DOM traversal method to target element
var elemns = tr.find("select[name*='piece_type'],.number");
//Reset value and trigger change event
elemns.val('').trigger('change');
}
//Reset table here.
function reset_table() {
$('table').find('input[type="text"], select').val('');
}
$("#service_type").change(reset_table);
$(document).on("click", "input[value='Delete']",...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.