javascript - Limit Sum Value of Multiple Input Fields -


i need javascript or jquery.

i have 3 (3) input fields want filter (sum of 3 fields).

the total value of 3 input fields must 100. if user fills more 100, automatically change value total 100.

you can see this example

<input type="text" name="text1" size="3"> text1<br /> <input type="text" name="text2" size="3"> text2<br /> <input type="text" name="text3" size="3"> text3<br />      <p>the maximum value of total 3 fields above 100.</p>     <pre>example 1 :      text1 : 20;     text2 : 30;     text3 : 50; (will automatically filled 50 because total value must 100)</pre>     <pre>example 2 :      text1 : 37;     text2 : 60;     text3 :  3; (will automatically filled 3 because total value must 100)</pre> 

thanks helping me, need :)

   $(function(){  $('input[name="text1"]').keyup(function(){      var text1value = $('input[name="text1"]').val();     if(text1value >=100)     {      $('input[name="text1"]').val(100);      $('input[name="text2"]').val('');      $('input[name="text3"]').val('');      $('input[name="text2"]').attr('disabled','disabled');       $('input[name="text3"]').attr('disabled','disabled');      }     else     {      $('input[name="text2"]').removeattr('disabled');       $('input[name="text3"]').removeattr('disabled');     } }); $('input[name="text2"]').keyup(function(){     var text1value = parseint($('input[name="text1"]').val());     var text2value = parseint($('input[name="text2"]').val());     if(isnan(text1value))     {      text1value =0;     }      if(isnan(text2value))     {      text2value =0;     }     var total = text1value + text2value;      if(total >=100)     {      $('input[name="text2"]').val(100-text1value);      $('input[name="text3"]').val('');      $('input[name="text3"]').attr('disabled','disabled');      }     else     {      $('input[name="text3"]').removeattr('disabled');      $('input[name="text3"]').val(100-total);     } });  }); 

i checking if sum of text boxes if exceeding 100, making correction in last entered textbox disabling next textbox.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -