JSFiddle - React, Tailwind, and code Playground

by itamark

HTML

<table>
<tr><td><input id="numberone"></input></td><td><input id="numbertwo"></input></td><td><span id="result"></span></td></tr>
</table>
<br>

<!--<select name="sweets" multiple="multiple">
    <option>Chocolate</option>
    <option selected="selected">Candy</option>
 
    <option>Taffy</option>
    <option selected="selected">Caramel</option>
    <option>Fudge</option>
    <option>Cookie</option>
 
  </select>
  <div></div>-->

CSS

span#result { color:red; }

JavaScript

//$("select").change(function () {
//  var str = "";
//  $("select option:selected").each(function () {
//            str += $(this).text() + " ";
//  });
//  $("div").text(str);
//})
//.change();

$("table tr").change(function(){
    var total = "0";
    $("td input#numberone").each(function(){
        numberone = $(this).val();
        numberone = parseInt(numberone);  
        numberone = numberone || 0;
    });
    $("td input#numbertwo").each(function(){
        numbertwo = $(this).val();
        numbertwo = parseInt(numbertwo);
        numbertwo = numbertwo || 0;

    });
    total = numberone + numbertwo;
    total = total || 0;
    $("span#result").text(total);
})
.change();