dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: need to make a loop for a layer hide/show function.

  1. #1
    Join Date
    May 2004
    Posts
    3

    Question need to make a loop for a layer hide/show function.

    i have designed a website containing about 150 layers that are 'visible' or 'hidden' by the click of a button.

    my problem is...
    ...that i've designed the entire website...
    ...and now i realize that the html document is too big...
    ...and is a bit slow when navigating...

    i haven't had much experience when it comes to loops...
    ...so i've ignored this idea until now...
    ...and now i'm stuck with the situation of having to add loops to reduce the size of the site...

    can anyone tell me what the best way to loop the following function is?

    function kwshow(a,b,c)
    {
    if(ie4)
    {
    if(a)
    { document.all.kw1.style.visibility="visible";
    document.all.ikw1.style.visibility="visible"; }
    else
    { document.all.kw1.style.visibility="hidden";
    document.all.ikw1.style.visibility="hidden"; }
    if(b)
    { document.all.kw2.style.visibility="visible";
    document.all.ikw2.style.visibility="visible"; }
    else
    { document.all.kw2.style.visibility="hidden";
    document.all.ikw2.style.visibility="hidden"; }
    if(c)
    { document.all.kw3.style.visibility="visible";
    document.all.ikw3.style.visibility="visible"; }
    else
    { document.all.kw3.style.visibility="hidden";
    document.all.ikw3.style.visibility="hidden"; }
    }
    else
    {
    if(a)
    { document.kw1.visibility="visible";
    document.ikw1.visibility="visible"; }
    else
    { document.kw1.visibility="hidden";
    document.ikw1.visibility="hidden"; }
    if(b)
    { document.kw2.visibility="visible";
    document.ikw2.visibility="visible"; }
    else
    { document.kw2.visibility="hidden";
    document.ikw2.visibility="hidden"; }
    if(c)
    { document.kw3.visibility="visible";
    document.ikw3.visibility="visible"; }
    else
    { document.kw3.visibility="hidden";
    document.ikw3.visibility="hidden"; }
    }
    }

    any help would be much appreciated...
    ...many thanks...

    ryan.

  2. #2
    Join Date
    Dec 2003
    Location
    Netherlands
    Posts
    642
    if you have 150 elements then you should think about a serverside language...

  3. #3
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    I don't understand what you wanna do yet. How many buttons will there be, and how many layers become visible/hidden when you click each button?

  4. #4
    Join Date
    Dec 2003
    Location
    Netherlands
    Posts
    642
    Its hard to explain what server-side scripting can really do for you.

    I try... if you have a lot of data don't put them into a flat file...use a database. Based on different cases you can call the data from the database without switching 150 layers.

  5. #5
    Join Date
    May 2004
    Posts
    3

    not much time for server side database.

    i don't really have time at the moment to re-design the infrastucture of the site...

    ...all i'm trying to do for the time being...
    ...is reduce the size of the site with loops...
    ...and i'm just wondering if there is a way of making a loop out of this particular function...

    ...where i get stuck is...
    ...i make a while loop...
    ...using i=1 to start...
    ...then replace kw[1/2/3] with kw[i]...
    ...i'm not actually sure how to add the 'i'...
    ...should i put it in quotes like this: "...kw" +i+ "..."?
    ...i understand the logic of it at least...
    ...but i'm not sure what i should do with the (a,b,c) part of the function...
    ...how would the loop incorporate the 'if(a)' part of the function...
    ...when 'i++' is used to continue the loop...
    ...how would the if(a) then turn into 'if(b)'?

    i'm not sure how clear i'm being about this...
    ...but the point is...
    ...i need to know if there is any way of turning this into a loop...

    thanks.
    ryan.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles