Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: JavaScript looping problem

date posted 16th February 2004 19:50

On my second mail I pointeed out the bug.

You can't do;
var objBranch = document.getElementById(branch).style;

because the script needs objBranch to be an object with children,
which you loop over then you can get each objChild from the brnches
childNodes collection
as you loop and change the style.display property.

I reckon your function wants to look sdomething like this:

function showAllBranch(){
//get a pointer to the element
var objBranch = document.getElementById(branch);

///then you loop the childNodes array like this
for(i=0;i
> Thanks a lot for this Ron. Unfortunately I still can't get it working.
> I've changed my function to this...
> function showAllBranch(){
> //get a pointer to the element
> var objBranch = document.getElementById(branch);
>
> //then you loop the childNodes array like this
>
> for(i=0;i {
> objChild = objBranch.childNodes[i];
> objChild.display="block";
> }
> }
> and got an error. I've also tried amending this line as such...
>
> var objBranch = document.getElementById(branch).style;
>
> and still no luck. I'll upload a file later so you can have a look at the
> complete page. Hopefully it is something simple. It's been driving me
mad!
> Thanks again.
> Paul.
>
>
>
>
>
> Paul Cooper
> Internet Developer
> Intex Design
> http://www.intexdesign.net
>
>
>
>
>
> >From: ron [EMAIL REMOVED]
> >Reply-To: [EMAIL REMOVED]
> >To: "FN-FORUM / [EMAIL REMOVED] [EMAIL REMOVED]
> >Subject: RE: FN-FORUM: JavaScript looping problem
> >Date: 16 Feb 2004 10:05:28 -0000
> >
> >
> >Sorry it took so long to reply, I was banned from the pc this valentines
> >weekend! :{
> >
> >objects have a childNodes array available in the DOM.
> >
> >so you do:
> >
> >//get a pointer to the element
> >var objBranch = document.getElementById(branch);
> >
> >//then you loop the childNodes array like this
> >
> >for(i=0;i >{
> >objChild = objBranch.childNodes[i];
> >objChild.display="block";
> >}
> >
> >
> >
> >Little performance tip for you - switching from display none to display
> >block is hard for the browser.
> >
> >But any element with a position: absolute style will take no space in the
> >document flow, so you can use visibility: hidden instead.
> >
> >It's much easier for a browser to switch an element from hidden to
visible,
> >so I use this method on things like menus for a better response.
> >
> >HTH
> >Ron
> >
> >-----Original Message-----
> >From: [EMAIL REMOVED] [EMAIL REMOVED] Behalf Of Paul
> >Cooper
> >Sent: 15 February 2004 10:58
> >To: FN-FORUM / [EMAIL REMOVED]
> >Subject: FN-FORUM: JavaScript looping problem
> >
> >
> >
> >Hi
> >
> >I've got a JavaScript tree control function that works like this...
> >
> >function showBranch(branch){
> > var objBranch = document.getElementById(branch).style;
> > if(objBranch.display=="block")
> > objBranch.display="none";
> > else
> > objBranch.display="block";
> >}
> >
> >When this is triggered it displays a child node. I want to have another
> >function that opens all the child nodes on the menu. So something like
> >this...
> >
> >function showAllBranch(){
> > for (var i=0;i > var objBranch = document.getElementById('branch')+i.style;
> > objBranch.display="block";
> > i++;
> > }
> >}
> >
> >The part I can't work out is how to pass the counter value into
objBranch.
> >So this bit is wrong...
> >
> >('branch')+i
> >
> >In ActionSript I'd do something like this...
> >
> >["branch"+i]
> >
> >I've tried all combinations I can think of but none work. Does anyone
know
> >the correct syntax?
> >
> >TIA
> >Paul.
> >
>
> _________________________________________________________________
> Tired of 56k? Get a FREE BT Broadband connection
> http://www.msn.co.uk/specials/btbroadband
>
>
> --
> ** Get all the Freelance Work you Can Handle *
> The Web Design Business Kit will show you proven tactics
> and strategies for marketing your business, winning bids,
> managing projects and pricing your work. Free Shipping Worldwide.
> Read more & get free chapters at:
http://www.sitepoint.com/launch/b7c91e/3/4
>
> To advertise here: http://www.freelancers.net/advertising.html
>
>



Messages by Day
February 29th 2004
February 28th 2004
February 27th 2004
February 26th 2004
February 25th 2004
February 24th 2004
February 23rd 2004
February 22nd 2004
February 21st 2004
February 20th 2004
February 19th 2004
February 18th 2004
February 17th 2004
February 16th 2004
February 15th 2004
February 14th 2004
February 13th 2004
February 12th 2004
February 11th 2004
February 10th 2004
February 9th 2004
February 8th 2004
February 7th 2004
February 6th 2004
February 5th 2004
February 4th 2004
February 3rd 2004
February 2nd 2004
February 1st 2004


Messages by Month
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
January 2004


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000