## 3 replies

Last post Jul 29, 2018 06:02 AM by vahid bakkhi

• chnar

Member

49 Points

154 Posts

### multiply two column

i have this table i want to multiply second column with third column then find sum of them

<table id="table_item" border="1">
<tr>
<th>n1</th>
<th>n2</th>
<th>n3</th>
</tr>

<tr>
<td><input type="text" value="2"></td>
<td><input type="text" value="4"></td>
<td><input type="text" value="3"></td>
</tr>

<tr>
<td><input type="text" value="1"></td>
<td><input type="text" value="6"></td>
<td><input type="text" value="8"></td>
</tr>
</table>

<script>

var sum=0;
for (var i = 1; i < \$("#table_item tr").length; i++) {

var d=parseFloat(\$("#table_item tr:eq('" + i + "') td:eq(1) input").val())*
parseFloat(\$("#table_item tr:eq('" + i + "') td:eq(2) input").val());

sum+=d;

}

</script>

• vahid bakkhi

Star

8059 Points

2780 Posts

### Re: multiply two column

Jul 29, 2018 05:34 AM|vahid bakkhi|LINK

hi

what's do you mean exactly?

do you want to multiply each row in column 2 with each row in colum3 and as result show sum of the multiply?

vahid bakhtiary

• chnar

Member

49 Points

154 Posts

### Re: multiply two column

yes excatly i need that

i want this result

4*3=12
6*8=48

sum=60
put this sum in textbox

• vahid bakkhi

Star

8059 Points

2780 Posts

### Re: multiply two column

Jul 29, 2018 06:02 AM|vahid bakkhi|LINK

you can try below script

```<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>

\$(function () {
var col2 = [];
var col3 = [];
var mul = [];
\$("#table_item td:nth-child(2)").each(function (index) {
col2.push(\$(this).find("input[type=text]").val());
});
\$("#table_item td:nth-child(3)").each(function (index) {
col3.push(\$(this).find("input[type=text]").val());
});

for (var i = 0; i < col2.length; i++) {
mul.push(parseInt(col2[i]) * parseInt(col3[i]));
}

var sum = 0;
for (var i = 0; i < mul.length; i++) {
sum = sum + parseInt(mul[i]);

}

})

</script>
```

```<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>

\$(function () {
var col2 = [];
var col3 = [];
var mul = [];
\$("#table_item td:nth-child(2)").each(function (index) {
col2.push(\$(this).find("input[type=text]").val());
});
\$("#table_item td:nth-child(3)").each(function (index) {
col3.push(\$(this).find("input[type=text]").val());
});

for (var i = 0; i < col2.length; i++) {
mul.push(parseInt(col2[i]) * parseInt(col3[i]));
}

var sum = 0;
for (var i = 0; i < mul.length; i++) {
sum = sum + parseInt(mul[i]);

}

})

</script>
<table id="table_item" border="1">
<tr>
<th>n1</th>
<th>n2</th>
<th>n3</th>
</tr>

<tr>
<td><input type="text" value="2"></td>
<td><input type="text" value="4"></td>
<td><input type="text" value="3"></td>
</tr>

<tr>
<td><input type="text" value="1"></td>
<td><input type="text" value="6"></td>
<td><input type="text" value="8"></td>
</tr>
</table>

```

vahid bakhtiary