Would I be able to do this?

Discussion in 'JavaScript' started by x0x, Jan 22, 2010.

  1. #1
    I use this script for expanding and collapsing my menus:

    http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm


    My question is since this:

    <a href="javascript:animatedcollapse.toggle('<?=$results[id]?>')"><img src="image.jpg" border="0" align="absmiddle"></a>

    expands/collapses the list. Would I be able to collapse and open all menus at once?

    $results[id] is a number from 1 to whatever the loop brings...
     
    x0x, Jan 22, 2010 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Yes, you will be able to do it, but for that you will have to do little modification in script. Or rather, write a javascript function, which calls collapse on all menu items which you wish to expand / collapse at once..
     
    mastermunj, Jan 23, 2010 IP
  3. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I'm not very good with javascript, actually I am a total noob. Could you give me a hint?

    I prefer going with a function.
     
    Last edited: Jan 23, 2010
    x0x, Jan 23, 2010 IP
  4. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #4
    OK, I figured something out by what I found on the demo page...


    <a href="javascript:animatedcollapse.show(['1', '2', '3'])">Show Examples 1, 2, 3</a> | <a href="javascript:animatedcollapse.hide(['1', '2', '3'])">Hide Examples 1, 2, 3</a></b>


    That collapses '1', '2' and '3'

    The problem here is that sometimes I might have over 50 lists. Would this method still be a smart way to do this? PHP loops generate the lists.



    For each list it also generates this new line:

    <script>
    animatedcollapse.addDiv('<?=$results[id]?>', 'fade=1', 'hide=1')
    </script>

    <a href="javascript:animatedcollapse.toggle('<?=$results[id]?>')"><img src="image.jpg" border="0" align="absmiddle"></a>






    Which means that
    <script>
    animatedcollapse.addDiv('<?=$results[id]?>', 'fade=1', 'hide=1')
    </script>

    is needed for each list.

    Would it be possible to skip the

    <script>
    animatedcollapse.addDiv('<?=$results[id]?>', 'fade=1', 'hide=1')
    </script>

    line or make just one line so one size fits all? And then use the animatedcollapse.show/hide function to collapse open all of them?
     
    x0x, Jan 23, 2010 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Yeah, that should do the work. The script already has provision to expand / collapse multiple div at a time.
    Well, with 50 divs I would suggest, you write a javascript function, which will call expande / collapse on each div in loop.

    Give it a try on simple html first, and then you can integrate it in your application / website.
     
    mastermunj, Jan 23, 2010 IP
  6. x0x

    x0x Well-Known Member

    Messages:
    510
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #6
    I tried and I failed. I've created another loop in php to collect the ids and pass it to js.

    I tried to do in javascript too but it did not work.

    Can you keep adding values to a variable like in php?

    lala .= ""+ numb + "";

    numb is what the loop brings
     
    x0x, Jan 24, 2010 IP