<
script
type
=
"text/javascript"
>
$
(
'#insert'
).
on
(
'click'
,
function
(){
var
code
=
$
(
'#inputCode'
).
val
();
var
price
=
$
(
'#inputPrice'
).
val
();
var
qty
=
$
(
'#inputQty'
).
val
();
$
.
ajax
({
url:
"
<?php
echo
base_url
()
?
>
stock/insertData"
,
method:
"POST"
,
data:
{
code:code
,
price:price
,
qty:qty
},
success
:
function
(
data
)
{
$
(
'#so_data tr:last'
).
after
(
data
);
// after i append New row
}
});
// i want to update total
// but total is not summing all rows ( exclude new row )
updateTotals
();
});
function
updateTotals
() {
var
tot
=
$
(
"#so_data tbody tr>td:nth-child(6)"
).
map
(
function
()
{
return
parseFloat
(
$
(
this
).
text
().
replace
(
/,/
g
,
""
) );
}).
get
().
reduce
(
sum
);
alert
(
tot
);
$
(
"#txtTotal"
).
val
(
tot
);
}
function
sum
(
a
,
b
)
{
return
a
+
b
}
</script>