Search code examples
javascriptjqueryfirebugkeypress

Get error "ReferenceError: event is not defined"


On project exists next js-function

function LoginKeyPressCheck() {
$('#txtusername, #txtpassword').keypress(function (evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode; // here get error
    $('#Errormsg').html('');
    $('#Err_ValidateUser').html('');
    if (charCode === 13) {
        evt.preventDefault();
        $('#Err_ValidateUser').html('');
        if ($.trim($('#txtusername').val()).length === 0) {
            $('#Err_ValidateUser').html('Validation Error: Value is required');
        }
        else {
            loginProcess();
        }
    }
});

When click button TAB get error "ReferenceError: event is not defined".

Try to debug this function in FireBug but from line var charCode = (evt.which)... cursor moves in else block.

I can't get where is problem.

Thanks.


Solution

  • Change this line

    var charCode = (evt.which) ? evt.which : evt.keyCode;
    

    variable event was not defined, so you can not use it