Reputation: 931
The code below throws Uncaught ReferenceError: categoryID is not defined error, what is wrong with it?
function selectCategory(obj) {
var categoryId;
categoryId=obj.getAttribute("data-category-id");
if ((document.getElementById("sCategory").value) != categoryID)
{
document.getElementById("sCategory").value = categoryID;
$.fancybox.close(".category-selection-fancybox-popup");
$.cookie("categoryId", categoryID, { expires : 360 });
$('.search').submit();
} else {
$.fancybox.close(".category-selection-fancybox-popup");
}
}
Upvotes: 0
Views: 317
Reputation: 1104
Variables are case sensitive in javascript. In fact JavaScript is a case-sensitive language completely. You have declared your variable like var categoryId;
and in your if condition you are using Capital D at end of variable name -> != categoryID
and in $.cookie("categoryId", categoryID
as well.
Upvotes: 3
Reputation: 98
JavaScript is a case-sensitive language. And so the likely cause is that you are referring to categoryId
as categoryID
on the following lines;
document.getElementById("sCategory").value = categoryID;
$.cookie("categoryId", categoryID, { expires : 360 });
Upvotes: 2