|
|
 |
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
>
> |
 |
|