Results 1 to 8 of 8

Thread: Any Javascript Guru's?

  1. #1
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts

    Any Javascript Guru's?

    Code:
    <script type="text/javaScript">
    <!--
    function getCookie(name) {
      var dc = document.cookie;
      var prefix = name + "=";
      var begin = dc.indexOf("; " + prefix);
      if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
      } else
        begin += 2;
      var end = document.cookie.indexOf(";", begin);
      if (end == -1)
        end = dc.length;
      return unescape(dc.substring(begin + prefix.length, end));
    }
    
    // LIST ALL SHOW/HIDE ELEMENT IDS HERE
    menus_array = new Array ('ddIT', 'ddLegal', 'ddMining', 'ddEnergy', 'ddChemicals', 'ddConstruction', 'ddAviation', 'ddServices');
    menus_status_array = new Array ();// remembers state of switches
    img_close = 'http://www.ibeats.co.uk/wp-content/themes/ibeats/images/collapse.gif';
    img_open = 'http://www.ibeats.co.uk/wp-content/themes/ibeats/images/expand.gif';
    
    function showHideSwitch (theid) {
      if (document.getElementById) {
        var switch_id = document.getElementById(theid);
        var imgid = theid+'Button';
        var button_id = document.getElementById(imgid);
        if (menus_status_array[theid] != 'show') {
          button_id.setAttribute ('src', img_close);
          switch_id.className = 'showSwitch';
    	  menus_status_array[theid] = 'show';
    	  document.cookie = theid+'=show';
        }else{
          button_id.setAttribute ('src', img_open);
          switch_id.className = 'hideSwitch';
    	  menus_status_array[theid] = 'hide';
    	  document.cookie = theid+'=hide';
        }
      }
    }
    function resetMenu () { // read cookies and set menus to last visited state
      if (document.getElementById) {
        for (var i=0; i<menus_array.length; i++) {
          var idname = menus_array[i];
          var switch_id = document.getElementById(idname);
          var imgid = idname+'Button';
          var button_id = document.getElementById(imgid);
          if (getCookie(idname) == 'show') {
    	    button_id.setAttribute ('src', img_close);
            switch_id.className = 'showSwitch';
    	    menus_status_array [idname] = 'show';
    	  }else{
    	    button_id.setAttribute ('src', img_open);
            switch_id.className = 'hideSwitch';
    	    menus_status_array [idname] = 'hide';
    	  }
        }
      }
    }
    //-->
    </script>
    This code is for a show/hide div, but it's defaulting as 'hide' - as seen here to the right of the page...

    Any idea how to set it to open as default?

  2. #2
    NOT Banned
    Join Date
    Jan 2007
    Posts
    5,905
    Thanks
    412
    Thanked
    278 times in 253 posts

    Re: Any Javascript Guru's?

    you could put in the body tag onload=showHide(DDIt)

  3. #3
    Spinal Pap Tomahawk's Avatar
    Join Date
    Jul 2003
    Location
    Bristol/Manchester Uni
    Posts
    1,002
    Thanks
    8
    Thanked
    13 times in 8 posts

    Re: Any Javascript Guru's?

    Quote Originally Posted by Vini View Post
    This code is for a show/hide div, but it's defaulting as 'hide' - as seen here to the right of the page...

    Any idea how to set it to open as default?
    Seems to be line 118 of your page, which read:
    Code:
    if (getCookie(idname) == 'show') {
    Which if you want it to open by default should be changed to read:
    Code:
          if (getCookie(idname) != 'show') {
    That should sort the problem... or you could use the method mentioned by moogle.

    Think I've misunderstood something in your code hah... worth trying. Also worth noting your menu does open by default when the page loads but it is immediately closed.. so I'm guessing its something to do with the cookie possibly?!
    Last edited by Tomahawk; 01-05-2008 at 07:24 PM.


    [ iTomaHawk | My Music MySpace ]

  4. #4
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts

    Re: Any Javascript Guru's?

    Quote Originally Posted by Tomahawk View Post
    Seems to be line 118 of your page, which read:
    Code:
    if (getCookie(idname) == 'show') {
    Which if you want it to open by default should be changed to read:
    Code:
          if (getCookie(idname) != 'show') {
    That should sort the problem... or you could use the method mentioned by moogle.

    Think I've misunderstood something in your code hah... worth trying. Also worth noting your menu does open by default when the page loads but it is immediately closed.. so I'm guessing its something to do with the cookie possibly?!
    Ok, applied this 'fix', anyone able to confirm it does indeed open, and stay open when visiting?

  5. #5
    Spinal Pap Tomahawk's Avatar
    Join Date
    Jul 2003
    Location
    Bristol/Manchester Uni
    Posts
    1,002
    Thanks
    8
    Thanked
    13 times in 8 posts

    Re: Any Javascript Guru's?

    I'm getting this error being flagged:

    button_id has no properties
    iBeats.co.uk
    Line 118
    From your code I don't really understand what you've used the cookie for to be honest? ..but it is definitely to do with the cookie you are creating and setting with the open/close state. As I just blocked cookies from your domain and did a hard refresh and the menu stayed open by default.


    [ iTomaHawk | My Music MySpace ]

  6. #6
    I R Toff Pandi! TAKTAK's Avatar
    Join Date
    Mar 2008
    Location
    Vergon6
    Posts
    7,450
    Thanks
    553
    Thanked
    1,013 times in 748 posts
    • TAKTAK's system
      • Motherboard:
      • ASUS ROG STRIX B450-F GAMING
      • CPU:
      • Ryzen 7 3700X
      • Memory:
      • 16GB Corsair Vengeance LPX 3200MHz
      • Storage:
      • 500GB Samsung 970 EVO
      • Graphics card(s):
      • 5700 XT 50th Anniversary
      • PSU:
      • Be Quiet SFX-L 600W
      • Case:
      • Lian Li PC-O11 Mini
      • Operating System:
      • Windows 10
      • Monitor(s):
      • LG Ultrawide
      • Internet:
      • 200Mb FTTP

    Re: Any Javascript Guru's?

    the menu is default open for me
    Post Counts and Other Rewards, Rules, Folding@Home, Fans: Push vs Pull vs Push-Pull, Corsair PSU OEMs.

    Quote Originally Posted by razer121 View Post
    Would you like me to enter you? it would be my pleasure
    TAKTAK.co.uk

  7. #7
    Squeeler Vini's Avatar
    Join Date
    Jul 2003
    Location
    Sheffield
    Posts
    1,769
    Thanks
    44
    Thanked
    8 times in 8 posts

    Re: Any Javascript Guru's?

    Quote Originally Posted by Tomahawk View Post
    I'm getting this error being flagged:



    From your code I don't really understand what you've used the cookie for to be honest? ..but it is definitely to do with the cookie you are creating and setting with the open/close state. As I just blocked cookies from your domain and did a hard refresh and the menu stayed open by default.

    Cookie is used to remember the state of the menu on users visit...

  8. #8
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Any Javascript Guru's?

    Quote Originally Posted by Vini View Post
    Ok, applied this 'fix', anyone able to confirm it does indeed open, and stay open when visiting?
    Why not delete the cookie and test it yourself?
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. javascript popup
    By hatsumi in forum Software
    Replies: 0
    Last Post: 28-12-2007, 01:17 AM
  2. Replies: 6
    Last Post: 22-11-2006, 02:58 PM
  3. Replies: 2
    Last Post: 06-11-2006, 12:05 PM
  4. JavaScript Help
    By Areku in forum Software
    Replies: 5
    Last Post: 25-05-2006, 03:27 PM
  5. Mixing Javascript with ASP in Overlib..
    By Stoo in forum Software
    Replies: 2
    Last Post: 13-09-2005, 07:21 AM

Posting Permissions

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