I have set up a workspace area which represents a blank PDF page where users can select paper size, orientation and elements they would like to add to the page. The user can place elements on the workspace that they are also capable of dragging and dropping.

When a user changes the orientation I need all the checked items to be briefly saved, which I am putting into an array. Then uncheck all the checkboxes and remove all the elements, which seems to be working as well. However, when I am trying to loop through the array to go back and check the checkboxes and call the function (BoardElement) which runs the ajax call, is not working.

The related code I am using is below. The OrientationChange function is what I am using to attempt the save, remove and call to BoardElement which gets the elements.

Code:
$(document).ready
(
function ()
{
	BoardElement = function ()
	{
		var elements_array = new Array('wai_img_', 'wai_text_', 'mission_text_', 'affirmation_text_', 'gratitude_text_', 'role_model_');
		if ($(this).is(':checked'))
		{
			var data_string = 'board_element=' + $(this).val();
			$.ajax
			({
				type: 'POST',
				url: 'get_board_element_ajax.php',
				data: data_string,
				success: function(html)
				{
					$('#board_area').append(html);
					$('.draggable_item').draggable
					({
						containment: '#board_area',
						stack: '#board_area div'
					});
				}
			});
		}
		else
		{
			var checked_value = $(this).val();
			$('.draggable_item').each
			(
			function ()
			{
				if (this.id.indexOf(elements_array[checked_value]) > -1)
				{
					$('#' + this.id).remove();
				}
			});
		}
	}
	$('input[id^=board_ele_]').click(BoardElement);


	// save, remove and get selected board items on orientation change
	OrientationChange = function ()
	{
		var board_ele_array = new Array();
		// save
		$('input[id^=board_ele_]').each
		(
		function (i)
		{
			if ($('#board_ele_' + i).is(':checked'))
			{
				$('#board_ele_' + i).attr('checked', false);
				board_ele_array.push(i);
				$('#board_ele_' + i).attr('checked', false);
			}
		});
		//for (var j = 0; j < board_ele_array.length; j++)
		//{
		var j = 0;
		function BoardEleCheckbox ()
		{
			if (j < board_ele_array.length)
			{
				//$('#board_ele_' + board_ele_array[j]).attr('checked', true);
				//$('#board_ele_' + board_ele_array[j]).click();
				//BoardElement();
				$('#board_ele_' + board_ele_array[j]).click
				(
				function ()
				{
					BoardElement();
				});
				j++;
				setTimeout(BoardEleCheckbox, 1000);
			}
		}
		setTimeout(BoardEleCheckbox, 1000);
		//}
	}
	$('input[name=orientation]').click(OrientationChange);

});