0

I am using a javascript code to show a invisible . The invisible is only appearing after clicking on textbox tb1.

I am using an SQL query to fill the text in textbox tb1.

I am using the following code:

<script type="text/javascript">
 $(window).load(function(){
  $('#tb1').on('change', function() {
   if($(this).val() != ""){
    $("#area2").show();    
   }
  });
 $('#tb1').focus('change', function() {
  $("#area2").show();
  });    
 }); // Closes window.load
</script>

Is there a way to show area2 when the text of textbox tb1 is changed? Without clicking on it?

John
  • 904
  • 8
  • 22
  • 56
  • Possible duplicate of [Detect all changes to a (immediately) using JQuery](http://stackoverflow.com/questions/1948332/detect-all-changes-to-a-input-type-text-immediately-using-jquery) – Spencer Wieczorek May 27 '16 at 00:35
  • The `propertychange change click keyup input paste` solution didnt work for me. The
    gets only visible after clicking or changing the textbox manually not when the textbox is changed from an SQL query
    – John May 27 '16 at 00:48
  • There are several solutions on the page. If necessary (*which is likely true for this case*) you can use the timer solution, the current accepted answer. If you are using ajax you might get around it by checking the `complete` function state via method. – Spencer Wieczorek May 27 '16 at 00:52
  • So my textbox needs to look like this? ` ` – John May 27 '16 at 00:59

1 Answers1

0

You can write a even listener on checkBox, So whenever there will be change in the value it will show area2. Above code can be written in this way to listen the event.

<script type="text/javascript">
 $(window).load(function(){
  $('#tb1').on("change keyup",function(e){
  if(this.value!==undefined || this.value!==null || $.trim(this.value)!=="" ) {
    $("#area2").show();    
   }
  });
 $('#tb1').focus('change', function() {
  $("#area2").show();
  });    
 }); // Closes window.load
</script>
Vijendra Kumar Kulhade
  • 2,217
  • 3
  • 15
  • 25
  • The OP isn't using a check box, and they are not using their mouse or key input to change the value. The value is changed from an SQL query, as in not by user click or key events. – Spencer Wieczorek May 27 '16 at 00:34
  • I am not using a check box or something, just a textbox – John May 27 '16 at 00:45