Question: I want to check if the input is empty or not **while the user is typing**

this is my code 

```
$('#visitID').on('change', function () {
        if ($('#visitID').val().length == 0) {
            $("#saveandclosebutton").hide();
        } else {
            $("#saveandclosebutton").show();
        }
    });

```

but the `saveandclosebutton` never becomes hidden even though if my input is empty.

Answer: 
You could include checking on `keyup` as well, e.g:

```
$('#visitID').on('change keyup', function () {
  this.value ? $("#saveandclosebutton").show() : $("#saveandclosebutton").hide();
});

```

[**jsFiddle here**](http://jsfiddle.net/b2XmK/3/)

Of course you'd need to set the button to be `display:none` initally, as your `<input>` would originally be empty.

```
#saveandclosebutton {
   display:none;
}

```
I guess that the `saveandclosebutton` is called differently. Try first to see if the main logic is working at all:

```
$('#visitID').on('change keyup', function () {
      console.log($('#visitID').val().length);
});

```

and check if the console has any output at all. You can add the `keyup` as I did so that the check is done after each keypress.