I have an HTML like ,
<table>
<tr>
<td><input type="text" data-column="A" value="5" data-row="1" /></td>
<td><input type="text" data-column="B" value="2" data-row="1" /></td>
</tr>
<tr>
<td><input type="text" value="7" data-column="A" data-row="2" /></td>
<td><input type="text" value="9" data-column="B" data-row="2" /></td>
</tr>
<tr>
<th><input type="text" data-column="A" data-row="3" data-equation="A1+A2-B1" /> </th>
<th><input type="text" data-column="B" data-row="3" data-equation="B1+B2" /></th>
</tr>
</table>
And my javascript like
$('input').each(function(){
if($(this).attr('data-equation')!=undefined){
var equation=$(this).attr('data-equation');
$(this).val(calculate(equation))
}
});
function calculate(equation){
result=0;
//calculate value and return,i dont know how to calculate
return result;
}
I need to calculate the value based on data-equation,In the equation ,First element refer data-column and second refer data-row