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: 
Bind the event handler to both the `keyup` and `change` events, but you also want to cause the event handler to get executed when the page loads:

```
$('#visitID').on('keyup change', function() {
    $('#saveandclosebutton').toggle($(this).val().length > 0);
}).change();

```

[jsfiddle](http://jsfiddle.net/29DSq/)
Try Keyup. Change it to:

```
$('#visitID').keyup(function () {
        var len = $('#visitID').val().length;
        if ( len == 0)
            $("#saveandclosebutton").hide();
        else
            $("#saveandclosebutton").show();
    });

```