Limit the Textbox value by taking into account the sum of its values

Asked

Viewed 52 times

0

I have the following table in which are included 3 textbox’s corresponding to percentages, what pregnant is that when the user inserts the values in the first 2 Textbox’s , the 3rd value appears with the value left of the subtraction of 100 with the sum of the other two textbox’s. For example, if it is written in the 1st textb’s the value of 50 , and in the 2nd the value of 25, it must appear in the 3rd automatically the value of 25. Can be in Javascript or Jquery.

<table id="myTable6">
  <thead>
      <tr>
           <th><label>Peso das Nota</label></th>
      </tr>
  </thead>
    <tbody>
        <form><td><label>Testes: </label><input type="text" name="nome" id="mySelect11"> 
                  <label>Exame:  </label><input type="text" name="nome" id="mySelect12">
                  <label>Trabalhos:</label>  <input type="text" name="nome" id="mySelect13"></td>


    </tbody>
</table>

1 answer

1


$("#mySelect12").on("blur",function(){
  var valor1 = parseFloat($("#mySelect11").val());
  var calc = 100 - (parseFloat($(this).val()) + valor1);
  $("#mySelect13").val(calc);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="myTable6">
  <thead>
    <tr>
      <th>
        <label>Peso das Nota</label>
      </th>
    </tr>
  </thead>
  <tbody>
    <form>
      <td>
        <label>Testes:</label>
        <input type="text" name="nome" id="mySelect11">
        <br><br>
        <label>Exame:</label>
        <input type="text" name="nome" id="mySelect12">
        <br><br>
        <label>Trabalhos:</label>
        <input type="text" name="nome" id="mySelect13">
      </td>
  </tbody>
</table>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.