Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get error "ReferenceError: event is not defined" [closed]

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.

like image 808
demo Avatar asked Nov 23 '25 01:11

demo


1 Answers

Change this line

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

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

like image 163
Oleksandr T. Avatar answered Nov 25 '25 15:11

Oleksandr T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!