rollOrDie Posted October 8, 2008 Share Posted October 8, 2008 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 (); Quote Link to comment Share on other sites More sharing options...
rochakchauhan Posted October 11, 2008 Share Posted October 11, 2008 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/ Quote Link to comment Share on other sites More sharing options...
emehrkay Posted October 12, 2008 Share Posted October 12, 2008 I dont understand your return result array. You run a loop, but define new Arrray() in every iteration...does it return more than one result? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.