0

I am using following html form code...

<li><input type="text" class="paytax" name="payment[tax][]" /> <input type="text" class="payship" name="payment[shiping][]" /> <input type="text" class="paytotal" name="payment[total][]" /></li>
<li><input type="text" class="paytax" name="payment[tax][]" /> <input type="text" class="payship" name="payment[shiping][]" /> <input type="text" class="paytotal" name="payment[total][]" /></li>
<li><input type="text" class="paytax" name="payment[tax][]" /> <input type="text" class="payship" name="payment[shiping][]" /> <input type="text" class="paytotal" name="payment[total][]" /></li>
<li><input type="text" class="paytax" name="payment[tax][]" /> <input type="text" class="payship" name="payment[shiping][]" /> <input type="text" class="paytotal" name="payment[total][]" /></li>

I am trying to get total of .paytax and .paytax ($('.paytax').val()+$('.payship').val();) but its adding total of first li input to each .paytotal, please help me with proper code.

thanks for support.

2 Answers 2

2

My assumption (without seeing any javascript code) is that you're trying to show the total in each line item. Tax + Shipping = Total. This code accomplishes that.

$(".paytax,.payship").live("keyup", function() {
    var $li = $(this).closest("li");
    var tax = parseFloat($li.find(".paytax").val());
    var ship = parseFloat($li.find(".payship").val());
    if(isNaN(tax)) tax = 0;
    if(isNaN(ship)) ship = 0;
    $li.find(".paytotal").val(tax + ship);
});
Sign up to request clarification or add additional context in comments.

5 Comments

its not working, i think you have forgot to add .keyup or change function on input boxes.
He didn't forget anything. You forgot to actually say that that's what you wanted. Please be more clear in the future if you expect answers to be accurate to your requirements.
I think you forgot to mention that you wanted it on keyup!
thats right, i am sorry if i couldn't provide proper information, what i want to do is, i am appending these fields using jquery and user can create upto 10 fields and each <li> total should be different according to passed value of .paytax and .payship
My answer should work fine for you. If you're going to ask people for help, PLEASE take the time to write a proper question with all the relevant information.
2
var total = 0;
$('input.paytax, input.payship').each(function() {
    total += parseFloat($(this).val());
});

This will total all the inputs of either of those classes.

UPDATE:

I see now what you're trying to do. You want line-by-line totals... Missed that. Go with the other posted answer (Jesse Gavin's). Mine will total the entire thing.

4 Comments

would it total .paytax and .payship?
Wouldn't what be ".paytax" and ".payship"? Oh, you want to tally both? See update.
are we still missing keyup or change function on inputs?
Your question made no mention of either of those things. See my comment on Jessegavin's post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.