0

Hello so here is my html

<li><label for=secure>Account #</label><input id="ID_1" name="ID_1"  required></li>
<li><label for=secure>Account #</label><input id="ID_2" name="ID_2"  required></li>
<li><label for=secure>Account #</label><input id="ID_3" name="ID_3"  required></li>

these are populated dynamically. I would like to put get the total amount of all these fields (they are numeric). I believe I would have to use the each function in jquery but I am not sure how to go about using it in this specific situation.so pretty much the sum of each input that has an id that starts with ID_

1
  • You could grab the non-dynamic part.. input[id*="ID_"] as a jQuery selector Commented Nov 23, 2013 at 22:38

1 Answer 1

4
var total = 0;

$('[id^="ID_"]').each(function(_, el) {
    total += +(el.value);
});
Sign up to request clarification or add additional context in comments.

1 Comment

great adeneo..i was answering with usual code..this is way better! upvote for you!

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.