Jump to content

Assigning a function result to a variable


rollOrDie

Recommended Posts

I have a result that is returned from housingDivAssign () that Im trying to assign to a variable inside the function setEvent ().

 

However I just get the error "is not a function". Is this because Im using it inside another function?

 

function housingDivAssign ()
{
	var housingDiv = document.getElementsByTagName ('div');

	j = 0
	for (i = 0; i < housingDiv.length; i ++)
		{
			if (housingDiv[i].className == 'housingHide')
				{
					var housingSection = new Array ();
					housingSection[j] = housingDiv[i];
					alert (j + ' = ' + housingDiv[i].id);
					j ++;
				}
		}

	return housingSection;
}


function housingTitleAssign ()
{
	var housingTitle = document.getElementsByTagName ('span');

	j = 0
	for (i = 0; i < housingTitle.length; i ++)
		{
			if ((housingTitle[i].className == 'title') || (housingTitle[i].className == 'titleTop'))
				{
					var housingSectionTitle = new Array ();
					housingSectionTitle[j] = housingTitle[i];
					// alert (j + ' = ' + housingTitle[i].id);
					j ++;
				}
		}

	return housingSectionTitle;
}

function setEvent ()
		{
			/* for (i = 0; i < housingSectionTitle.length; i ++)
				{
					alert (housingSectionTitle[i].id);
				} */
			var housing = housingDivAssign ();
			alert (housing[2].id);
		}

setEvent ();

Link to comment
Share on other sites

No you can call function inside another function... the reason is because you are calling setEvent() before  your HTML page is rendered.

 

Solutions: Either call setEvent ();  inside onLoad  or call it on some event like onclick..  it will work

 

To know more... check out:

 

 

http://rochakchauhan.com/blog/2008/09/25/most-common-javascript-mistakes/

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.