I'm creating my own tagging "thingy" which will function similar to Stack Overflow's.
However, my tags require me to check against two categories(arrays), AmericanCodes and CanadianCodes. If the tag does not exist in either of the two arrays, I need to deal with it differently.
Everything seems to be working fine, with the exception of my $.inArray functionality.
It is acting as if it is found in the first array every time. (You'll see what i mean when you view the Fiddle)
Here is my code: Fiddle link below
$(document).ready(function () {
var AmericanCodes = ["AA", "AB", "AC", "AD", "AE", "AF"]; // Known american conversion codes
var CanadianCodes = ["CA", "CB", "CC", "CD", "CE", "CF"]; // Known canadian conversion codes
var UnknownCodes = []; // Collects Unrecognized Codes
var Entry = $("input#RecessiveCodes"); // Set Input
$(Entry).keypress(function (e) { //
if (e.keyCode == 32) { // This is the enter key
var EntryValue = $(Entry).val(); // Get Input
console.log(EntryValue);
if ($.inArray(EntryValue, AmericanCodes) < 0) { // Check if it's an american code
$("ul#EnteredCodes").append("<li class='AR'>", EntryValue, "</li>") // Style knowns slightly different than unkown
} else if ($.inArray(EntryValue, CanadianCodes) < 0) { // Check if it's an canadian code
$("ul#EnteredCodes").append("<li class='CR'>", EntryValue, "</li>") // Style knowns slightly different than unkown
} else {
UnknownCodes.push($(EntryValue)); //Add to list but store unknown reccessive seperatley
$("ul#EnteredCodes").append("<li class='UR'>", EntryValue, "</li>") // Style unknowns slightly different
}
$(Entry).val("");
}
});
});