How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
I am making a module where if I click on a product item it will add cart list by append method. after appending any item the price of each append item will summation. and then show this result of summation on another id such as an id name sub_total
Here is my append code
$('#selectedMenu').append('<tr class="menu-row"><td><input type="text" class="price no-style" name="menu_price" id="menu_price" value="' + data.price + '"><input type="hidden" id="menu_hidden_price" value="' + data.price +'"></td><td><span class="btn btn-xs btn-danger"><i class="cancel fa fa-times"></i></span></td></tr>');
after append take all price by class named price and sum all price
$(document).on('click ready keyup change', '.price', function(){
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
});
The summation result will show on an input filed which is defined by an id named sub_total
<table class="table order-bill">
<tr>
<th>Sub Total</th>
<td><input type="text" value="0.00" class="no-style" id="sub_total"></td>
</tr>
<tr>
<th>Total</th>
<td><input type="text" value="0.00" class="no-style" id="total_price"></td>
</tr>
</table>
javascript jquery ajax
add a comment |
I am making a module where if I click on a product item it will add cart list by append method. after appending any item the price of each append item will summation. and then show this result of summation on another id such as an id name sub_total
Here is my append code
$('#selectedMenu').append('<tr class="menu-row"><td><input type="text" class="price no-style" name="menu_price" id="menu_price" value="' + data.price + '"><input type="hidden" id="menu_hidden_price" value="' + data.price +'"></td><td><span class="btn btn-xs btn-danger"><i class="cancel fa fa-times"></i></span></td></tr>');
after append take all price by class named price and sum all price
$(document).on('click ready keyup change', '.price', function(){
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
});
The summation result will show on an input filed which is defined by an id named sub_total
<table class="table order-bill">
<tr>
<th>Sub Total</th>
<td><input type="text" value="0.00" class="no-style" id="sub_total"></td>
</tr>
<tr>
<th>Total</th>
<td><input type="text" value="0.00" class="no-style" id="total_price"></td>
</tr>
</table>
javascript jquery ajax
1
What is your question?
– Pal Singh
Jan 2 at 9:19
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
@BelalKhan look at specification of.each
if index is equal to length of.price
elements - 1 than$('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.
– Belal Khan
Jan 2 at 9:41
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42
add a comment |
I am making a module where if I click on a product item it will add cart list by append method. after appending any item the price of each append item will summation. and then show this result of summation on another id such as an id name sub_total
Here is my append code
$('#selectedMenu').append('<tr class="menu-row"><td><input type="text" class="price no-style" name="menu_price" id="menu_price" value="' + data.price + '"><input type="hidden" id="menu_hidden_price" value="' + data.price +'"></td><td><span class="btn btn-xs btn-danger"><i class="cancel fa fa-times"></i></span></td></tr>');
after append take all price by class named price and sum all price
$(document).on('click ready keyup change', '.price', function(){
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
});
The summation result will show on an input filed which is defined by an id named sub_total
<table class="table order-bill">
<tr>
<th>Sub Total</th>
<td><input type="text" value="0.00" class="no-style" id="sub_total"></td>
</tr>
<tr>
<th>Total</th>
<td><input type="text" value="0.00" class="no-style" id="total_price"></td>
</tr>
</table>
javascript jquery ajax
I am making a module where if I click on a product item it will add cart list by append method. after appending any item the price of each append item will summation. and then show this result of summation on another id such as an id name sub_total
Here is my append code
$('#selectedMenu').append('<tr class="menu-row"><td><input type="text" class="price no-style" name="menu_price" id="menu_price" value="' + data.price + '"><input type="hidden" id="menu_hidden_price" value="' + data.price +'"></td><td><span class="btn btn-xs btn-danger"><i class="cancel fa fa-times"></i></span></td></tr>');
after append take all price by class named price and sum all price
$(document).on('click ready keyup change', '.price', function(){
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
});
The summation result will show on an input filed which is defined by an id named sub_total
<table class="table order-bill">
<tr>
<th>Sub Total</th>
<td><input type="text" value="0.00" class="no-style" id="sub_total"></td>
</tr>
<tr>
<th>Total</th>
<td><input type="text" value="0.00" class="no-style" id="total_price"></td>
</tr>
</table>
javascript jquery ajax
javascript jquery ajax
edited Jan 2 at 9:22
Belal Khan
asked Jan 2 at 9:15
Belal KhanBelal Khan
163
163
1
What is your question?
– Pal Singh
Jan 2 at 9:19
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
@BelalKhan look at specification of.each
if index is equal to length of.price
elements - 1 than$('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.
– Belal Khan
Jan 2 at 9:41
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42
add a comment |
1
What is your question?
– Pal Singh
Jan 2 at 9:19
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
@BelalKhan look at specification of.each
if index is equal to length of.price
elements - 1 than$('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.
– Belal Khan
Jan 2 at 9:41
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42
1
1
What is your question?
– Pal Singh
Jan 2 at 9:19
What is your question?
– Pal Singh
Jan 2 at 9:19
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
@BelalKhan look at specification of
.each
if index is equal to length of .price
elements - 1 than $('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
@BelalKhan look at specification of
.each
if index is equal to length of .price
elements - 1 than $('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.– Belal Khan
Jan 2 at 9:41
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.– Belal Khan
Jan 2 at 9:41
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42
add a comment |
2 Answers
2
active
oldest
votes
I create a function and call this function in the event which event is append the following raw.
function summationMenyPrice() {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
}
add a comment |
The problem is the css selector, you should use the class of the product container
$(document).on('click ready keyup change', '.price', function(){
Change it to
$(document).on('click ready keyup change', '.<CONTAINER-CLASS-HERE>', function(){
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003778%2fhow-to-sum-of-price-in-jquery-after-append-raw-in-a-table-and-show-all-price-in%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I create a function and call this function in the event which event is append the following raw.
function summationMenyPrice() {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
}
add a comment |
I create a function and call this function in the event which event is append the following raw.
function summationMenyPrice() {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
}
add a comment |
I create a function and call this function in the event which event is append the following raw.
function summationMenyPrice() {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
}
I create a function and call this function in the event which event is append the following raw.
function summationMenyPrice() {
var sum = 0;
$('.price').each(function() {
sum += Number($(this).val());
});
$('#sub_total').val(sum);
}
answered Jan 2 at 9:50
Belal KhanBelal Khan
163
163
add a comment |
add a comment |
The problem is the css selector, you should use the class of the product container
$(document).on('click ready keyup change', '.price', function(){
Change it to
$(document).on('click ready keyup change', '.<CONTAINER-CLASS-HERE>', function(){
add a comment |
The problem is the css selector, you should use the class of the product container
$(document).on('click ready keyup change', '.price', function(){
Change it to
$(document).on('click ready keyup change', '.<CONTAINER-CLASS-HERE>', function(){
add a comment |
The problem is the css selector, you should use the class of the product container
$(document).on('click ready keyup change', '.price', function(){
Change it to
$(document).on('click ready keyup change', '.<CONTAINER-CLASS-HERE>', function(){
The problem is the css selector, you should use the class of the product container
$(document).on('click ready keyup change', '.price', function(){
Change it to
$(document).on('click ready keyup change', '.<CONTAINER-CLASS-HERE>', function(){
answered Jan 2 at 9:58
ma_dev_15ma_dev_15
409211
409211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003778%2fhow-to-sum-of-price-in-jquery-after-append-raw-in-a-table-and-show-all-price-in%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What is your question?
– Pal Singh
Jan 2 at 9:19
How to sum of price in jquery after Append raw in a table and show all price in a id named sub_total
– Belal Khan
Jan 2 at 9:22
@BelalKhan look at specification of
.each
if index is equal to length of.price
elements - 1 than$('#sub_total').val(sum);
– Zydnar
Jan 2 at 9:40
$('#sub_total').val(sum);
here is no problem @Zydnar, I have solved my problem now. My problem was in the jquery event.– Belal Khan
Jan 2 at 9:41
@BelalKhan In this case I suggest you to answer this question by yourself to make it closed.
– Zydnar
Jan 2 at 9:42