Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
Old 11-26-2005, 11:45 AM show/hide script
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
Can someone help me with a script to make my nav display/hide...

Code:
<table width="150px" class="mininav" cellpadding="3" cellspacing="0">
	<tr>
		<td>
			<div align="center">Control Panel</div>
			-<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
			-<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />
			-<a href="index.php?page=cp&settings">Settings</a><br />
		</td>
	</tr>
</table>
how can i make it so that when you click on the - next to "profile" (same for "diary" as well) it expands to show the sublinks "View profile" and "Edit profile" and then when you click it again it hides them...

xx kieran xx
-_darkranger_- is offline
View Public Profile
 
 
Register now for full access!
Old 11-26-2005, 12:41 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Here a simple script:
Code:
function showhide(id){
  if(document.getElementById(id).style.display=="none")
    document.getElementById(id).style.display="block";
  else
    document.getElementById(id).style.display="none";
}
You'd better put your table in a div however. I've got bad experiences when doing this directly with tables.
HTML Code:
<div id="nav">
  <table width="150px" class="mininav" cellpadding="3" cellspacing="0">
    <tr>
      <td>
        <div align="center">Control Panel</div>
        -<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
        -<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />
        -<a href="index.php?page=cp&settings">Settings</a><br />
      </td>
    </tr>
  </table>
</div>
<a href="javascript:showhide('nav')">Show/hide Navgation</a>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Orodreth; 11-26-2005 at 12:47 PM..
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 11-26-2005, 02:20 PM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
thx it work brilliantly :P i gave you so talkupation

hehe anyway is there anyway of making it so it automaticaly doesnt show and then once the person clicks to open it, it sets a cookie to remember that its open so it is open on every page?
-_darkranger_- is offline
View Public Profile
 
Old 11-26-2005, 05:23 PM
Unknown.

Posts: 1,693
Trades: 0
This post might help..
http://webmaster-talk.com/showthread...2215#post65289
Dark-Skys99 is offline
View Public Profile
 
Old 11-26-2005, 07:14 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Yeah, indeed, you could do it that way. Chroder's good in JavaScript, I'd never have figured this out. Anyways, for use with my script, here's an altered version:

HTML Code:
<html>
<head>
  <title> New Document </title>
  <script language="javascript" type="text/javascript">
  <!--
   function getCookie(name){
    if(document.cookie!=""){
      var cookie=document.cookie;
      var start=cookie.indexOf(name);
      var stop;

      if(start!=-1){
        start+=name.length+1;
        stop=cookie.indexOf(';', start);

        if(stop==-1)
          stop=cookie.length;
        return unescape(cookie.substring(firstPos, lastPos));
      }
    }
    else
      return false;
  }

  function makeCookie(name, value){
    var cookie = name + '=' + escape(value) + ';';
    document.cookie = cookie;
  }

  function showhide(id, setcookie=true){
    if(setcookie==true){
      var cookie=getCookie('show');
      var show=new Array();
      show=cookie.split(', ');
      var in=-1;

    for(i=0; i < show.length; i++)
      if(show[i]==id)
        in=i;
    }

    if(document.getElementById(id).style.display=="none"){
      document.getElementById(id).style.display="block";

      if(in==-1 && setcookie==true)
        show[show.length]=id;
    }
    else{
      document.getElementById(id).style.display="none";

      if(in!=-1 && setcookie==true)
        show.splice(in, 1);
    }

    if(setcookie==true)
      makeCookie('show', show.join(', '));
  }

  function init(){
    showhide('nav', false)

    var cookie=getCookie('show');
    var show;

    if(cookie){
      show=cookie.split(', ');

      for(i=0; i < show.length; i++)
        document.getElementById(show[i]).style.display="block";
    }
  }
  -->
  </script>
</head>

<body onload="init()">
  <div id="nav">
    <table width="150px" class="mininav" cellpadding="3" cellspacing="0">
      <tr>
        <td>
          <div align="center">Control Panel</div>
          -<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
          -<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />
          -<a href="index.php?page=cp&settings">Settings</a><br />
        </td>
      </tr>
    </table>
  </div>
  <a href="javascript:showhide('nav')">Show/hide Navgation</a>
</body>
</html>
That should do the job. The script above makes all elements in the cooki show, the rest won't. Make sure to hide these (either by calling the showhide() function, like I did in the init() function, or directly through css).

I didn't test it, so it's probably still full of bugs.

Thanks for the talkreputation, BTW.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Orodreth; 11-26-2005 at 07:19 PM..
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-03-2005, 05:29 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
Quote:
Originally Posted by Orodreth
Yeah, indeed, you could do it that way. Chroder's good in JavaScript, I'd never have figured this out. Anyways, for use with my script, here's an altered version:

HTML Code:
<html>
<head>
  <title> New Document </title>
  <script language="javascript" type="text/javascript">
  <!--
   function getCookie(name){
    if(document.cookie!=""){
      var cookie=document.cookie;
      var start=cookie.indexOf(name);
      var stop;

      if(start!=-1){
        start+=name.length+1;
        stop=cookie.indexOf(';', start);

        if(stop==-1)
          stop=cookie.length;
        return unescape(cookie.substring(firstPos, lastPos));
      }
    }
    else
      return false;
  }

  function makeCookie(name, value){
    var cookie = name + '=' + escape(value) + ';';
    document.cookie = cookie;
  }

  function showhide(id, setcookie=true){
    if(setcookie==true){
      var cookie=getCookie('show');
      var show=new Array();
      show=cookie.split(', ');
      var in=-1;

    for(i=0; i < show.length; i++)
      if(show[i]==id)
        in=i;
    }

    if(document.getElementById(id).style.display=="none"){
      document.getElementById(id).style.display="block";

      if(in==-1 && setcookie==true)
        show[show.length]=id;
    }
    else{
      document.getElementById(id).style.display="none";

      if(in!=-1 && setcookie==true)
        show.splice(in, 1);
    }

    if(setcookie==true)
      makeCookie('show', show.join(', '));
  }

  function init(){
    showhide('nav', false)

    var cookie=getCookie('show');
    var show;

    if(cookie){
      show=cookie.split(', ');

      for(i=0; i < show.length; i++)
        document.getElementById(show[i]).style.display="block";
    }
  }
  -->
  </script>
</head>

<body onload="init()">
  <div id="nav">
    <table width="150px" class="mininav" cellpadding="3" cellspacing="0">
      <tr>
        <td>
          <div align="center">Control Panel</div>
          -<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
          -<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />
          -<a href="index.php?page=cp&settings">Settings</a><br />
        </td>
      </tr>
    </table>
  </div>
  <a href="javascript:showhide('nav')">Show/hide Navgation</a>
</body>
</html>
That should do the job. The script above makes all elements in the cooki show, the rest won't. Make sure to hide these (either by calling the showhide() function, like I did in the init() function, or directly through css).

I didn't test it, so it's probably still full of bugs.

Thanks for the talkreputation, BTW.
argh... i tried that and it wont work :S i cant really fix it cause i dont no javascript ... please could someone help me sort it out?
-_darkranger_- is offline
View Public Profile
 
Old 12-03-2005, 06:00 AM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Are you using firefox? If you are, could you send me the error message (found in the JavaScript-console)
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-03-2005, 06:05 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
nowp im using ie but i do have firefox so ill go check it out on firefox now
-_darkranger_- is offline
View Public Profile
 
Old 12-03-2005, 06:06 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
Error: missing ) after formal parameters
Source File: http://www.apocoliptic-children.gm6.info/aphoticdreams/
Line: 31, Column: 33
Source Code:
function showhide(id, setcookie=true){

Error: init is not defined

Error: toggleItem is not defined
-_darkranger_- is offline
View Public Profile
 
Old 12-04-2005, 07:02 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Ok, fixed. And I tested it this time:

HTML Code:
<html>
<head>
  <title> New Document </title>
  <script language="javascript" type="text/javascript">
  <!--
   function getCookie(name){
    if(document.cookie!=""){
      var cookie=document.cookie;
      var start=cookie.indexOf(name);
      var stop;

      if(start!=-1){
        start+=name.length+1;
        stop=cookie.indexOf(';', start);

        if(stop==-1)
          stop=cookie.length;
        return unescape(cookie.substring(start, stop));
      }
    }
    else
      return false;
  }

  function makeCookie(name, value){
    var cookie = name + '=' + escape(value) + ';';
    document.cookie = cookie;
  }

  function showhide(id, setcookie){
    if(setcookie==true){
      var cookie=getCookie('show');
      var show=new Array();
      if(cookie) {show=cookie.split(', ');}
      var invar=-1;

    for(i=0; i < show.length; i++)
      if(show[i]==id)
        invar=i;
    }

    if(document.getElementById(id).style.display=="none"){
      document.getElementById(id).style.display="block";

      if(invar==-1 && setcookie==true)
        show[show.length]=id;
    }
    else{
      document.getElementById(id).style.display="none";

      if(invar!=-1 && setcookie==true)
        show.splice(invar, 1);
    }

    if(setcookie==true)
      makeCookie('show', show.join(', '));
  }

  function init(){
    showhide('nav', false)

    var cookievalue=getCookie('show');
    var show;

    if(cookievalue){
      show=cookievalue.split(', ');

      for(i=0; i < show.length; i++)
        document.getElementById(show[i]).style.display="block";
    }
  }
  -->
  </script>
</head>

<body onload="init()">
  <div id="nav">
    <table width="150px" class="mininav" cellpadding="3" cellspacing="0">
      <tr>
        <td>
          <div align="center">Control Panel</div>
          -<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
          -<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />
          -<a href="index.php?page=cp&settings">Settings</a><br />
        </td>
      </tr>
    </table>
  </div>
  <a href="javascript:showhide('nav', true)">Show/hide Navgation</a>
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-05-2005, 04:32 PM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
yea it works thx but i cant open it back up :S
-_darkranger_- is offline
View Public Profile
 
Old 12-05-2005, 05:25 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Oh, darn. I'll try to fix it tomorrow, it's too late now.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-06-2005, 06:01 AM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
Ok, and now? You can test/view/download the fixed (I think) script here: http://thomas.weyn.be/scripts/showhide/page.html

Here's the code again
HTML Code:
<html>
<head>
  <title> New Document </title>
  <script language="javascript" type="text/javascript">
  <!--
   function getCookie(name){
    if(document.cookie!=""){
      var cookie=document.cookie;
      var start=cookie.indexOf(name);
      var stop;

      if(start!=-1){
        start+=name.length+1;
        stop=cookie.indexOf(';', start);

        if(stop==-1)
          stop=cookie.length;
        return unescape(cookie.substring(start, stop));
      }
    }
    else
      return false;
  }

  function makeCookie(name, value){
    var cookie = name + '=' + escape(value) + ';';
    document.cookie = cookie;
  }

  function showhide(id, setcookie){
    if(setcookie==true){
      var cookie=getCookie('show');
      var show=new Array();
      if(cookie) {show=cookie.split(', ');}
      var invar=-1;

    for(i=0; i < show.length; i++)
      if(show[i]==id)
        invar=i;
    }

    if(document.getElementById(id).style.display=="none"){
      document.getElementById(id).style.display="block";

      if(invar==-1 && setcookie==true)
        show[show.length]=id;
    }
    else{
      document.getElementById(id).style.display="none";

      if(invar!=-1 && setcookie==true)
        show.splice(invar, 1);
    }

    if(setcookie==true)
      makeCookie('show', show.join(', '));
  }

  function init(){
    showhide('nav', false)

    var cookievalue=getCookie('show');
    var show;

    if(cookievalue!=""){
      show=cookievalue.split(', ');

      for(i=0; i < show.length; i++)
        document.getElementById(show[i]).style.display="block";
    }
  }
  -->
  </script>
</head>

<body onload="init()">
  <div id="nav">
    <table width="150px" class="mininav" cellpadding="3" cellspacing="0">
      <tr>

        <td>
          <div align="center">Control Panel</div>
          -<a href="index.php?page=profile">Profile</a><br /><span class="mininav">-<a href="index.php?page=profile&user=-_DarkRanger_-">View Profile</a></span><br /><span class="mininav">-<a href="index.php?page=profile&do=edit">Edit Profile</a></span><br />
          -<a href="index.php?page=diary">Diary</a><br /><span class="mininav">-<a href="index.php?page=diary&user=-_DarkRanger_-">View Diary</a></span><br /><span class="mininav">-<a href="index.php?page=diary&do=new">New Diary</a></span><br />

          -<a href="index.php?page=cp&settings">Settings</a><br />
        </td>
      </tr>
    </table>
  </div>
  <a href="javascript:showhide('nav', true)">Show/hide Navgation</a>
</body>
</html>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Orodreth; 12-07-2005 at 06:30 AM..
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-10-2005, 10:21 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
thx

ive updated the script on my site but it still wont open back up and i dont know why because it works fine on your test page :S

my site is here if ya wanna look... http://www.apocoliptic-children.gm6....eams/index.php

the error message :S
Error: cookievalue has no properties
Source File: http://www.apocoliptic-children.gm6....ams/index.php#
Line: 67

do you have any idea why it wont work on my site :S

i swear jscrip hates me ¬.¬ never works for me :S my jscript menu is messing up atm as well :S
-_darkranger_- is offline
View Public Profile
 
Old 12-10-2005, 10:25 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
btw the link to open and close the nav on the left is at the top left and it says "Show/Hide Nav"
-_darkranger_- is offline
View Public Profile
 
Old 12-10-2005, 08:51 PM
Ultra Talker

Posts: 251
Location: Belgium, Antwerp, Zoersel
Trades: 0
First thing that's wrong:
HTML Code:
<tr><td align="left"><a href="#" onclick="toggleItem('nav', true)">Show/Hide Nav</a></td></tr>
change to
HTML Code:
<tr><td align="left"><a href="#" onclick="showhide('nav', true)">Show/Hide Nav</a></td></tr>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Orodreth is offline
View Public Profile Visit Orodreth's homepage!
 
Old 12-11-2005, 11:32 AM
-_darkranger_-'s Avatar
Super Talker

Posts: 122
Location: bolton...
Trades: 0
oooooooh sorry >< hehe im blind
-_darkranger_- is offline
View Public Profile
 
Old 12-06-2007, 12:05 PM Re: show/hide script
Junior Talker

Posts: 1
Trades: 0
Hi, i may have a simple solution, its not exactly what you wanted, but let me show it:



<script type="text/javascript">





try {
function start() {
document.getElementById('test').style.display="non e"
}
}
catch(err) {
alert("er is iets fout gegaan")
}

try {

function verander() {

document.getElementById('test').style.display="blo ck"

}
}
catch(err) {
alert("er is iets fout gegaan")
}
</script>

</head>
<body>
<body onload="start()">

<input type="button" onClick="verander()" value="show">

<input type="button" onClick="start()" value="hide">
<div id="test">
<form>
<input type="text">
</form>
</div>



---ignore the catch and try
matteman is offline
View Public Profile
 
Old 12-06-2007, 12:21 PM Re: show/hide script
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
You'd better put your table in a div however. I've got bad experiences when doing this directly with tables.
That's because you cannot use display="block" on a table row or cell.
You have special display values for those.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
View Public Profile Visit tripy's homepage!
 
Old 12-06-2007, 02:32 PM Re: show/hide script
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Hi, i may have a simple solution, its not exactly what you wanted
Mind you, I would hope the problem was solved sometime ago, because it was posted in December ...

... 2005!!!!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Closed Thread     « Reply to show/hide script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.87204 seconds with 12 queries