Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <table>
    <thead>
      <th>Field 1</th>
      <th>Field 2</th>
      <th>Resultado</th>
    </thead>
    <tbody>
      <tr>
        <td><input type="text" value="2"/></td>
        <td><input type="text" value="3"/></td>
        <td class="result"><input type="text" value="5"/></td>
      </tr>
      <tr>
        <td><input type="text" value="4"/></td>
        <td><input type="text" value="5"/></td>
        <td class="result"><input type="text" value="9"/></td>
      </tr>
      <tr>
        <td><input type="text" value=""/></td>
        <td><input type="text" value=""/></td>
        <td class="result"><input type="text" /></td>
      </tr>
    </tbody>
  </table>
  <label>Total:</label>
  <label class="total"></label>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
</body>
</html>
 
function countResults() {
  var quantityResult = 0;
  $('.result input').each(function() {
    var resultElement = $(this);
    if(resultElement.val() !== "") {
      quantityResult++;
    }
  });
  return quantityResult;
}
function setTotal(totalValue) {
  $('.total').text(totalValue);
}
function initListenResultField() {
  $('.result input').keyup(function(event) {
    console.log('opa');
    var totalResult = countResults();
    setTotal(totalResult);
  });
}
// initialize
initListenResultField();
var totalResult = countResults();
setTotal(totalResult);
console.log(totalResult);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers