Show/Hide code help

Discussion in 'JavaScript' started by wakra, Dec 22, 2009.

  1. #1
    Hi i need some help with editing show/hide code it is works fine with me but it is show the content every time i refresh the page what i want is to be the conetent hidden till i click on the link to show the content so every time i refersh the page no thing appear untill i click on the show link.

    <head>tag
    <script type="text/javascript">
    <!--
    var storedDiv = null;
    function getDiv(oID) {
    if(document.getElementById) {
    return document.getElementById(oID);
    } else if( document.all ) {
    return document.all[oID];
    } else { return null; }
    }
    window.onload = function () {
    for( var i = 0, y; y = getDiv('ans'+i); i++ ) {
    y.style.display = 'none'
    }
    };
    function toggleInfo(oID) {
    var oDiv = getDiv(oID); if( !oDiv ) { return; }
    oDiv.style.display = (oDiv.style.display=='none') ? 'block' : 'none'
    if( storedDiv && storedDiv != oDiv ) { storedDiv.style.display = 'none'
    } storedDiv = oDiv;
    }
    //--></script>


    in <body>tag
    <span style="cursor: hand; cursor: pointer" onclick="toggleInfo('ans0');">
    >> Hide/show content
    </span><br><br>
    <div id="ans0">

    content

    </div>
     
    wakra, Dec 22, 2009 IP
  2. qasimbilal

    qasimbilal Member

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    36
    #2
    <script>
    function toggleInfo(myID){

    if(document.getElementById(myID).style.display=='none'){
    document.getElementById(myID).style.display='block';
    } else {
    document.getElementById(myID).style.display='none';
    }

    }
    </script>

    <span style="cursor: hand; cursor: pointer" onclick="toggleInfo('ans0');">
    >> Hide/show content
    </span><br><br>
    <div id="ans0">

    content

    </div>
     
    qasimbilal, Dec 22, 2009 IP
  3. wakra

    wakra Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks but this not change any thing i still see the content every time i referesh the page
     
    wakra, Dec 22, 2009 IP
  4. qasimbilal

    qasimbilal Member

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    36
    #4
    solve this problem using cookie
    set cookie value 1 when your div is visible and set cookie value 0 when div is hidden
    now on page load check the value of cookie if 1 then set your div visible and if cookie value is 0
    set div hidden

    Setting Cookie Using javaScript
    document.cookie = "name=value; expires=date; path=path;
    domain=domain; secure";

    i think this will solve your problem
     
    qasimbilal, Dec 23, 2009 IP