Skip to content

Instantly share code, notes, and snippets.

@jonperron
Last active February 1, 2017 10:19
Show Gist options
  • Save jonperron/46b6ce41374dd6eb1f753fe6cf8ed598 to your computer and use it in GitHub Desktop.
Save jonperron/46b6ce41374dd6eb1f753fe6cf8ed598 to your computer and use it in GitHub Desktop.
Check if field content is in an array.
<script type="text/javascript">
var contentArray = [
...
];
var testField = document.getElementById('test_field');
testField.onkeyup = function(){
if(contentArray.indexOf(testField.value) != -1) {
alert("It's in the array !");
} else {
alert("It's not in the array !");
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment