jquery - JavaScript not recognizing array declaration -


i'm trying check user input against predefined array of values ensure user entered valid input.

to this, i'm using jquery's $.inarray() function. takes 2 arguments: value checked, , array check with. returns index of value in array if found, , -1 if not.

however, when use $.inarray() function, not seem recognize genrearray array (see code below). while doesn't show here, genrearray variable not have proper syntax highlighting in function call. in addition, seems if if check gets carried out, nothing (not error) shows on console.

the if statement syntax working fine - replace code if (1 === 1) , code carried out fine.

in addition, placement of variable declaration not seem matter either. i've put before/after every important point in code, no difference in results.

i've ruled out problems genre variable.

thanks lot help.


$(document).ready(function() {   var genrearray = [...];    $('.menu').click(function() {     var genre = $('#genrename').val().split(' ').join('+');     $('#error').text('');     if ($.inarray(genre, genrearray) != -1) {       $('#error').text('sorry, not valid genre.');     }   }) }) 


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -