Jump to content

Elements are not being created


unemployment

Recommended Posts

Any idea why my elements are not being created?  Firebug doesn't return any errors and the ajax data is being submitted.

 

if (goal_title !== 'Goal Subject...' && goal_title.length > 0)
			{
				var goal_start_date 	= goal_start_year + '-' + goal_start_month + '-' + goal_start_day;
				var goal_end_date		= goal_end_year + '-' + goal_end_month + '-' + goal_end_day;

				ajax.post('/assets/ajax/goal_create.php', 'title=' + goal_title + '&status=' + goal_status + '&start_date=' + goal_start_date + '&end_date=' + goal_end_date + '&info=' + goal_info, function(resp)
				{
					//Remove all children of previous goals list and recreate the new one from var resp (holds all the data required)
					// Feel free to change the returned_goals variable name 

					var goals = eval('(' + resp + ')');

					var goal_list		= document.getElementById('goal_list');
					removeChildren(goal_list);

					alert(goal_list);
					console.log(goal_list);

					var goal_item 			=[];   
					var goal_holder 		=[];
					var goal_icon 			=[];
					var goal_icon_status 	=[];
					var goal_icon_img 		=[];
					var goal_identifier 	=[];
					var goal_list_items 	=[];
					var goal_ul 			=[];
					var goal_li_uncomplete 	=[];
					var goal_a_uncomplete 	=[];
					var goal_li_onhold 		=[];
					var goal_a_onhold		=[];
					var goal_li_cancelled	=[];
					var goal_a_cancelled	=[];
					var goal_li_completed	=[];
					var goal_a_completed	=[];
					var goal_status 		=[];
					var goal_name	 		=[];
					var goal_add_info	 	=[];
					var goal_end_date	 	=[];

					for (i = 0; i < goals[i].length; i++) 
					{
						alert(goals[i].length);
						console.log(goals[i].length);

						goal_item[i] 		= document.createElement('div');
						goal_holder[i] 		= document.createElement('div');
						goal_icon[i] 		= document.createElement('a');
						goal_icon_status[i] = document.createElement('div');
						goal_icon_img[i] 	= document.createElement('img');
						goal_identifier		= document.createElement('div');
						goal_list_items		= document.createElement('div');
						goal_ul				= document.createElement('ul');
						goal_li_uncomplete	= document.createElement('li');
						goal_a_uncomplete	= document.createElement('a');
						goal_li_onhold		= document.createElement('li');
						goal_a_onhold		= document.createElement('a');
						goal_li_cancelled	= document.createElement('li');
						goal_a_cancelled	= document.createElement('a');
						goal_li_completed	= document.createElement('li');
						goal_a_completed	= document.createElement('a');
						goal_status[i] 		= document.createElement('input');
						goal_name[i] 		= document.createElement('div');
						goal_add_info[i] 	= document.createElement('div');
						goal_end_date[i] 	= document.createElement('div');

						goal_item[i].className = 'goal_item_passed';

						goal_holder[i].className = 'goal_icon_holder mrs';

						goal_icon[i].href = 'javascript:void(0)';
						goal_icon[i].className = 'goal_icon_button';

						goal_icon_status[i].className = 'goal_icon uncompleted';

						goal_icon_img[i].src = '/assets/img/icons/' + goals[1][i].goal_status;

						goal_li_completed[i].appendChild(goal_a_completed[i]);
						goal_li_cancelled[i].appendChild(goal_a_cancelled[i]);
						goal_li_onhold[i].appendChild(goal_a_onhold[i]);
						goal_li_uncomplete[i].appendChild(goal_a_uncomplete[i]);

						goal_ul[i].appendChild(goal_li_completed[i]);
						goal_ul[i].appendChild(goal_li_cancelled[i]);
						goal_ul[i].appendChild(goal_li_onhold[i]);
						goal_ul[i].appendChild(goal_li_uncomplete[i]);

						goal_list_items[i].appendChild(goal_ul[i]);

						goal_identifier[i].appendChild(goal_list_items[i]);

						goal_icon[i].appendChild(goal_identifier[i]);

						goal_icon_status[i].appendChild(goal_icon_img[i]);
						goal_icon[i].appendChild(goal_icon_status[i]);
						goal_holder[i].appendChild(goal_icon[i]);

						goal_item[i].appendChild(goal_end_date[i]);
						goal_item[i].appendChild(goal_add_info[i]);
						goal_item[i].appendChild(goal_name[i]);
						goal_item[i].appendChild(goal_status[i]);
						goal_item[i].appendChild(goal_holder[i]);
						goal_list.appendChild(goal_item[i]);
					}
				});
			}

Link to comment
Share on other sites

Are you sure your for loop is correct?

 

for (i = 0; i < goals.length; i++)

 

Is the second statement supposed to be i<goals.length? I have no idea what is in "goals" since I don't have your PHP script's output...

 

Does the alert/console log in the for loop fire? What's the output?

Link to comment
Share on other sites

Well, what does resp contain?

 

You should really be using JSON as your response format.  Its native JavaScript, and it allows you to treat your response as an object (which it is - that's what the O stands for).

 

Also, take a look at your loop:

 

for(var i = 0; i < goals[i].length; i++)

 

Are you sure you want to check each goal element's length?  Or do you really want:

 

for(var i = 0; i < goals.length; i++)

 

?

 

99.9999....% of the time, the second version is correct.

Link to comment
Share on other sites

Well, what does resp contain?

 

You should really be using JSON as your response format.  Its native JavaScript, and it allows you to treat your response as an object (which it is - that's what the O stands for).

 

Also, take a look at your loop:

 

for(var i = 0; i < goals[i].length; i++)

 

Are you sure you want to check each goal element's length?  Or do you really want:

 

for(var i = 0; i < goals.length; i++)

 

?

 

99.9999....% of the time, the second version is correct.

 

I'll have to look into JSON and see how it works.  Have any documentation you could link me to that would give me a quick heads up / tutorial?

 

Thank you for fixing my problem as the second version was what I was looking for.  Looks like I got confused as I usually do with JS. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.