k961
k961

Reputation: 587

function is not working inside document.onkeydown

So I have a function :

$(document).ready(function () {
        function Next() {
            alert("IM GOING TO DO SOMETHING NOW");
        }
        document.onkeydown = function (e) 
        {
           if (!e) e = window.event;
           switch (e.keyCode) 
           {
            case 37:
                //alert("Left arrow");
                Next();
                break;
            } //End OnKeyDown

        }); //End Document load

In console says "Next() is not a function"

What am I doing wrong ?

UPDATE : OK i think since i was using jquery .next() and .prev() in other parts of the code it was not working i just changed the next() to go_next() and it works just fine

thanks

Upvotes: 0

Views: 351

Answers (1)

Stefan Seemayer
Stefan Seemayer

Reputation: 2067

You forgot closing braces on your switch statement (JSFiddle demo):

$( document ).ready(function() {
function Next() 
{
    alert("IM GOING TO DO SOMETHING NOW");
} 
    document.onkeydown=function(e){

        if (!e) e=window.event;
       switch(e.keyCode) {
        case 37:
             //alert("Left arrow");
            Next();
            break;
       }
} //End OnKeyDown

}); //End Document load

Upvotes: 1

Related Questions