SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    show/hide DIV problem with reload

    Hi friends,

    I have a problem that needs your help

    If you see this site: http://www.nosotroscinco.com

    you will see the button +info

    By clicking there, I show or hide a <div> using the below js function:

    **********************************
    <script language="javascript">
    function toggle() {
    var ele = document.getElementById("toggleText");
    if(ele.style.display == "block") {
    ele.style.display = "none";
    }
    else {
    ele.style.display = "block";
    window.scrollTo(100,300)
    }
    }
    </script>
    **********************************

    The problem I have here, is that each time the "next" or "prev" buttons are pressed (< or >) reload the page, and I want to reload the URL but with last status for the ele.style.display.

    I donīt know if I am clear enough, but for instance, I open the website home, then click in +info, it shows the hidden div, then click in next button ">", I want that +info is opened if previously it was opened.

    I really appreciate your help on this, I am driving crazy and cant solve this.

    Thanks & Best regards

  2. #2
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you can use php, you can store the display status of the div (dispStatus) in a session variable. Each time the +info is clicked you also update a hidden input element with the current display status.

    On each page load you check the value of the hidden element being passed to the page and then store it in a global javascript variable.

    Code:
     
    <script type="text/javascript?>
     
    var dispStatus = <?php  echo $_POST['txtDispStatus']; ?>;
     
    </script>
    If you have to do it on client side only, you can either use cookies to store the current display status or append the display status as a query string parameter the the page's url and then parse the quesry string on each page load to get the current display status.

  3. #3
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Kalon, I am already using php, but I am using GET, not post. If you click in < or >, you will see it in action.

    I donīt see how I can implement what you have sent to me, thankyou any way !

  4. #4
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thinking a bit more about it, yes GET would be easier.

    Just append the current status (dispStatus) in a query string to the url that your < and > point to and then use code along the lines of -

    Code:
     
    <script type="text/javascript">
     
    var dispStatus = <?php  echo $_GET['txtDispStatus']; ?>;  
     
    function toggle() {
         dispStatus = (dispStatus == 'block')? 'none' : 'block';
         elem.style.display = dispStatus;
    }
     
    window.onload=function() {
        elem = document.getElementById("toggleText");
        elem.style.display = dispStatus;
    }
     
    </script>

  5. #5
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Kalon, that would work fine, but not completely, since I have too an swf movie that links to other pages, and too need to pass the status that holds the javascript function, in this case I think itīs impossible.... not sure.

  6. #6
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rmurer View Post
    Thanks Kalon, that would work fine, but not completely, since I have too an swf movie that links to other pages, and too need to pass the status that holds the javascript function, in this case I think itīs impossible.... not sure.
    I'm not sure what you mean in the red text

  7. #7
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hahaha Kalon, the status for the div to be hidden/shown, is changed by the javascript function toggle(), and this status should be passed to the swf movie too, in order to click in next/prev buttons that this swf movie holds.

    Clear ? mmmm I don&#180;t think !!! my english suck

  8. #8
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    I am guessing if you want to do something with your SWF, you would need to use ActionScript within your SWF to grab/know where it is (next/prev)
    Ryan B | My Blog | Twitter

  9. #9
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rmurer View Post
    Clear ?
    no.


Bookmarks

Posting Permissions

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