I have this function of jquery for validation, how can it be changed to use with keypress events ?

```
function validate() {
        var stateID = $("#purpose").val();
            // var stateID = $(this).val();
        if (stateID == '') { 
              var validformula = true;
              var validweightq1 = true;
              var newpar = true;
              validformula = checkEmpty($("#formula"));
              validweightq1 = checkEmpty($("#weg"));
              newpar = checkEmpty($("#newparameter"));
                $("#btn-submit").attr("disabled",true);
              if(validweightq1 && validformula && newpar) {
                $("#btn-submit").attr("disabled",false);
                } 
        }

```

how to combine with on keypress ?

```
$(document).ready(function() {
    $('#purpose').on('keypress', function(key) {})
})

```