I have a function that gets the id's of all the checked and unchecked checkboxes then hides or shows the element depending if it's checked or not. My problem is that I'm getting:
TypeError: upperPos[this] is undefined upperPos[this].hide();
but Im not getting this error on upperPos[this].show(); (and the elements appear as they should)
jquery:
$('body').on('change', '.optionForm', function() {
var formId = $(this).attr('id'),
checked = new Array();
unchecked = new Array();
$('#' + formId + ' input:checked').each(function() {
checked.push($(this).attr('id'));
});
$('#' + formId + ' input:not(:checked)').each(function() {
unchecked.push($(this).attr('id'));
});
console.log(checked);
$.each(checked, function() {
upperPos[this].show();/*This does not have an error*/
});
console.log(unchecked);
$.each(unchecked, function() {
upperPos[this].hide();/*This is error*/
});
});
Both arrays are being populated correctly.
upperPos[] contains an array of raphael objects. The id's of the checkboxes correspond to the raphael objects and the function is supposed to hide/show them accordingly.
I would appreciate any help on why Im getting this error. If you need any additional info, please let me know.
Thanks, Adam
jsFiddle: http://jsfiddle.net/adam123/Jw9h5/60/
For some reason the fiddle works, but my code does not.