Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 113k

How to Compute Two TextBox Using Jquery

Mar 23 2017 2:05 PM
Dear code masters,
I believe you are all in good health.
I need your Assistance once again, my challenge is as follows:
Let say i have a webform in ASP.NET, that have two Textbox's Txt1 and Txt2
Txt1 is for previou tempratureand and it is readonly, when the form load previous data from Database is loaded into Txt1 so the user is expected to input current temprature into Txt2 we want Txt2 to validate Txt1 if it is not a space and if it is greater than or equal to zero. If that happens then
Txt1 = Txt1 + Txt2 else
Txt1 = Txt2.
I use Jqeury as follows:
  1. <script type="text/javascript" src="Scripts/jquery-3.1.1.min.js"></script>  
  2. <script type="text/javascript">  
  3.  $(function () {  
  4.   $('#<%=Text1.ClientID%>').blur(function sumN1() {  
  5.     var T = $('#<%=TextBox3.ClientID%>').val()  
  6.      if (T != "" && T >= 0) {  
  7.      $('#<%=Txt1.ClientID%>').val(+$('#<%=Txt1.ClientID%>').val() + +$('#<%=Txt2.ClientID%>').val());  
  8.      } else {  
  9.          $('#<%=Txt1.ClientID%>').val($('#<%=Txt2.ClientID%>').val());  
  10.      }  
  11.    })  
  12. })  
  13. </script>  
 
this code works fine, if Txt1 = 50 from load and the user input 10 in Txt2 the result in Txt1 = 60, but the challange is when the user input the wrong figure 10 instead of 5 and the user change it, it add it up so Txt1 became 65 but what we want is for Txt1 to change to 55.
how can we impliment this with the above Jquery.
Thank you all

Answers (3)