regex - Searching for partial matches an array using .grep and RegExp - Jquery -
im new-ish jquery , im stuck. i've build function search array , return matched word , definition(from array same index) , works fine.
now trying search partial matches. ive searched on stackoverflow , rest of internet try , figure out how work , why not working, im stuck.
heres code
$("#search").submit(function() { = $("#term").val(); if ($.inarray(a,glossary) > -1) { loc = $.inarray(a,glossary); $("#pterm").text(glossary[loc]); $("#definition").text(def[loc]); return false; }else if ($.grep(glossary, function(value) { var search = new regexp(a,"gi"); if (value.match(search))return true; return false;}) == true) { $("#pterm").text(" "); $("#definition").text("partial match found."); return false; }else { $("#pterm").text(" "); $("#definition").text("that term not found."); return false; } });
thanks help. -scott
Comments
Post a Comment