Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Need Help With Script - Collapsible Content...

    I have this script that i got from Dynamic Drive. its function is to collapse and expand content using cookies and such. Its very efficient. But i have a minor problem. How do i change it so the beginning state is expanded rather than collapsed.

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Contractible Headers script-  Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for legal use. Last updated Mar 23rd, 2004.
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
    var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)
    
    if (document.getElementById){
    document.write('<style type="text/css">')
    document.write('.switchcontent{display:none;}')
    document.write('</style>')
    }
    
    function getElementbyClass(classname){
    ccollect=new Array()
    var inc=0
    var alltags=document.all? document.all : document.getElementsByTagName("*")
    for (i=0; i<alltags.length; i++){
    if (alltags[i].className==classname)
    ccollect[inc++]=alltags[i]
    }
    }
    
    function contractcontent(omit){
    var inc=0
    while (ccollect[inc]){
    if (ccollect[inc].id!=omit)
    ccollect[inc].style.display="none"
    inc++
    }
    }
    
    function expandcontent(cid){
    if (typeof ccollect!="undefined"){
    if (collapseprevious=="yes")
    contractcontent(cid)
    document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
    }
    }
    
    function revivecontent(){
    contractcontent("omitnothing")
    selectedItem=getselectedItem()
    selectedComponents=selectedItem.split("|")
    for (i=0; i<selectedComponents.length-1; i++)
    document.getElementById(selectedComponents[i]).style.display="block"
    }
    
    function get_cookie(Name) { 
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { 
    offset += search.length
    end = document.cookie.indexOf(";", offset);
    if (end == -1) end = document.cookie.length;
    returnvalue=unescape(document.cookie.substring(offset, end))
    }
    }
    return returnvalue;
    }
    
    function getselectedItem(){
    if (get_cookie(window.location.pathname) != ""){
    selectedItem=get_cookie(window.location.pathname)
    return selectedItem
    }
    else
    return ""
    }
    
    function saveswitchstate(){
    var inc=0, selectedItem=""
    while (ccollect[inc]){
    if (ccollect[inc].style.display=="block")
    selectedItem+=ccollect[inc].id+"|"
    inc++
    }
    
    document.cookie=window.location.pathname+"="+selectedItem
    }
    
    function do_onload(){
    uniqueidn=window.location.pathname+"firsttimeload"
    getElementbyClass("switchcontent")
    if (enablepersist=="on" && typeof ccollect!="undefined"){
    document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
    firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
    if (!firsttimeload)
    revivecontent()
    }
    }
    
    
    if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
    else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
    else if (document.getElementById)
    window.onload=do_onload
    
    if (enablepersist=="on" && document.getElementById)
    window.onunload=saveswitchstate
    
    </script>
    
    <h3 onClick="expandcontent('sc1')" style="cursor:hand; cursor:pointer" align="center"><font color="#808080" size="3">Expand
    | Collapse</font></h3>
    <div id="sc1" class="switchcontent">
    <center><a href="http://www.mlsrepository.proboards81.com/index.cgi?action=pmsend&to=admin" target="_blank">
    <p style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><img src="http://img.photobucket.com/albums/v615/blacksabbath99/PES-Center/mlsrepository/avatars/Submit.gif" border="0" alt="Photo Sharing and Video Hosting at Photobucket" width="379" height="71"></a></center>
    
    <center>
      <table border="1" width="775" height="536" cellspacing="0" cellpadding="0" bgcolor="#EFEFEF" bordercolor="#c6c6c6" style="border-collapse: collapse">
        <tr>
          <td width="775" height="20" background="silvergrad_luke.jpg" colspan="2"> 
            <p style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font color="#C0C0C0">Chicago
            Fire Faces</font> </td>
        </tr>
        <tr>
          <td width="383" height="298" valign="top">
      </center>
    
    <center>
          </center>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="http://www.geocities.com/mlsrepository/Blanco.bin"><img border="0" src="http://img.photobucket.com/albums/v615/blacksabbath99/PES-Center/mlsrepository/FACES/81f4710811af45b3a542a66c4d94cba6.jpg" width="373" height="418"></a></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
          <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font size="4" face="Arial">Blanco</font></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
          <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><b><font size="2">Author:
          JayM07</font></b></p>
          <p align="center"> </td>
          <td width="391" height="298" valign="top">
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="http://www.geocities.com/mlsrepository/cbarret.bin"><img border="0" src="http://img.photobucket.com/albums/v615/blacksabbath99/ChadBarret.png" width="250" height="350"></a></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font size="4" face="Arial">Chad
      Barret</font></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><b><font size="2">Author:
      acdc</font></b></p>
            <p> </td>
        </tr>
        <tr>
          <td width="383" height="466" valign="top">
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="http://www.geocities.com/mlsrepository/conde.bin"><img border="0" src="http://img.photobucket.com/albums/v615/blacksabbath99/Conde.png" width="250" height="350"></a></p>
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font face="Arial" size="4">Wilman
            Conde</font></p>
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
            <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><b><font size="2">Author:
            acdc </font></b>
            <p style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0" align="center"> </td>
          <td width="391" height="466" valign="top">
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="http://www.geocities.com/mlsrepository/segarez4.bin"><img border="0" src="http://img237.imageshack.us/img237/9994/segarezsx2.png" width="250" height="350"></a></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font size="4" face="Arial">Gonzalo
      Segarez</font></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><b><font size="2">Author:
      acdc</font></b></p>
      <p> 
          </td>
        </tr>
        <tr>
          <td width="383" height="51" valign="top">
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><a href="http://www.geocities.com/mlsrepository/Wanchope_facek.bin"><img border="0" src="http://img.photobucket.com/albums/v615/blacksabbath99/PES-Center/mlsrepository/FACES/wanchope.jpg" width="342" height="360"></a></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><font size="4" face="Arial">Wanchope</font></p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"> </p>
      <p align="center" style="line-height: 100%; word-spacing: 0; margin-top: 0; margin-bottom: 0"><b><font size="2">Author:
      s'n</font></b></p>
            <p> </td>
          <td width="391" height="51" valign="top">
       
          </td>
        </tr>
    <tr>
          <td width="774" height="25" valign="top" colspan="2">
            <p align="center"><font size="2">The files used in this site have been
            authorized by their respective creators.</font></td>
    </tr>
      </table>
    
    </div>

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    Code:
    document.write('.switchcontent{display:none;}')
    probally needs to be
    Code:
    document.write('.switchcontent{display:block;}')
    and then anyplace in the script says "none" probally needs to be block and visa versa.

    Didn't read or test the script so start with the first part and see if that affects it correctly.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    acdc992004 (10-02-2007)

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    thanks man, that worked. I had to replace all blocks with none and vice versa


  •  

    Posting Permissions

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