I have an input field, #tag_field, where my users enter a tag, which I would then like to check if the specified value exists in the JSON object.
Included below is the code that I’m currently using but am not sure how to pass the user input to the function on the blur() event.
var tags = [
{
"tag": "php",
"id": "x&8j"
},
{
"tag": "ruby",
"id": "x&8jX90"
}
];
$j('#tag_field').blur(function(){
var tagMap = {};
var i = null;
for (i = 0; tags.length > i; i += 1) {
tagMap[tags[i].tagName] = tags[i];
}
var hasTag = function(tagName) {
return tagMap[tagName];
};
});
Do you mean some like this
Do you just need to take the value of the input and compare it to the names in your tags object?