William Isted William Isted - 3 months ago 12
jQuery Question

Uncaught SyntaxError: Unexpected string

I'm having difficulty getting the following to work, all I get from Chrome's Console is

Uncaught SyntaxError: Unexpected string
.

I have tried
tmp = event.keyCode
and changing
tmp
in the
if
statement to
event.keyCode
but I cannot identify the problem.



function showSearching() {
alert ("Hello World");
}

$('#search').bind('keydown', function() {
tmp = Number(event.keyCode);
if ( ( tmp=<"48" && tmp=>"90" ) || ( tmp=<"96" && tmp=>"111" ) || ( tmp=<"186" && tmp=>"222" ) ) {
showSearching();
}
});

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<input id="search" type="text">




Answer

Wrong syntax of relational operator in if statement.

change => to >= and =< to <=

$('#search').bind('keydown', function() {
    tmp = Number(event.keyCode);
    if ((tmp  <= "48" && tmp  >= "90") || (tmp  <= "96" && tmp  >= "111") || (tmp  <= "186" && tmp  >= "222")) {
        showSearching();
    }
});‚Äč
Comments