Abraham Olatubosun

Abraham Olatubosun

  • NA
  • 471
  • 107.5k

How to check if TextBox control has value in JQuery

Mar 4 2017 12:13 AM

I want to check some Textbox control if they have value do some addition else do assignment, I used the JQuery script below it didn't work for me.

The idea is on key up it should call the JQuery Function to check if TextBox797 have value then sum up the value of TextBox651 and TextBox797 else replace the value of TextBox797 with value of TextBox651. it not showing any result

 
  1. <ASP:TextBox ID="TextBox651" runAt="server" onKeyUp="CheckIT()" />   
  2.   
  3. <ASP:TextBox ID="TextBox797" runAt="server"  />  

this is the JQ script i have in the Function

  1. function CheckIT()   
  2. {  
  3.       if ($('#<%=TextBox797.ClientID%>').val() != ""   
  4.      && $('#<%=TextBox797.ClientID%>').val() >= 0) {  
  5.   
  6.   document.getElementById('<%=TextBox797.ClientID%>').value =   
  7.           parseInt(document.getElementById('<%=TextBox797.ClientID%>').value) +   
  8.           parseInt(document.getElementById('<%=TextBox651.ClientID%>').value);  
  9.   
  10. else {  
  11.   
  12.   document.getElementById('<%=TextBox797.ClientID%>').value =   
  13.           parseInt(document.getElementById('<%=TextBox651.ClientID%>').value);  
  14.   
  15. }  
  16.   

 please is their any other way to write the JQuery to do the job ?
Thank you
 
 
 
 
 

Answers (3)