Here is the code I am working with:
$(document).ready(function () {
var TemplateEditor = function () {
var GroupClassName = 'group';
var SelectedGroup = 0;
var BindClicks = function () {
$('.CriteriaSelections').unbind('click').click(function (event) {
event.preventDefault();
if (fnIsTheClickedBoxaGroup($(this))) {
TemplateEditor.GroupClicked();
}
else {
TemplateEditor.CriteriaClicked($(this), SelectedGroup);
}
});
$('.groupselected').unbind('click').click(function (event) {
event.preventDefault();
SelectedGroup = $(this).attr('group-'.length);
TemplateEditor.SelectGroup(SelectedGroup);
});
}
var fnGetGroupID = function (Obj) {
if (fnIsTheClickedBoxaGroup(Obj) == true) {
return null;
}
else {
//Get parent which is the group
var ObjParent = Obj.parent();
var GID = ObjParent.attr('id').substr('group-'.length);
return GID;
}
}
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
return {
Init: function () {
BindClicks();
},
CriteriaClicked: function (Obj, GroupID) {
$('<div>').attr({ id: '' }).addClass('selection').text(Obj).appendTo('#group-' + GroupID);
},
GroupClicked: function () {
},
SelectGroupClicked: function () {
},
UpdateTargetPanel: function () {
}
};
} ();
TemplateEditor.Init();
});
I am trying to access this variable: GroupClassName
This variable is inside this function
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
When I run the program it says GroupClassName is undefined. Am I missing something here?
alert(GroupClassName)in the fnIsTheClickedBoxaGroup function. I see no reason why GroupClassName shouldn't be set when you get to it. Also, do you accidentally say var GroupClassName multiple times? Do you use incorrect capitalization?var x = function(){...}) with semicolons, your code technically has syntax errors and might not work in all browsers. In general, take a look at what JSLint (jslint.com) has to say about your code.