JSFiddle - React, Tailwind, and code Playground

by shijin

HTML

<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>

JavaScript

$('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 to result and return,i dont know how to calculate
    return result;
}