[SOLVED] Show&Hide Div Box

This is a discussion on "[SOLVED] Show&Hide Div Box" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Show&Hide Div Box are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Sep 29th, 2007, 13:21
Junior Member
Join Date: Sep 2007
Location: Romania
Age: 38
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Post [SOLVED] Show&Hide Div Box

Hello,
I have a show&hide div box js. and i want to invert the function on it.
I mean, when i open the page when the script are instaled, the script is set to show the div box, and have the option to Close the div box;
I want to invert the function like when i open the page, to not show the div box , just the "OPEN" option to open the div box and close then if the users want.
Here is my JS. file:
Code: Select all
var flag
function closeDivArea(name, name2){
    if (this[name+"_flag"]==undefined){
        this[name+"_flag"] = false
    }
    this[name+"_flag"] = !this[name+"_flag"];
    var obj = document.getElementById(name);
    obj.style.display = (this[name+"_flag"]==false)? "" : "none";
    
    var obj = document.getElementById(name2);
    obj.innerHTML = (this[name+"_flag"]==false)? "CLOSE" : "OPEN";
}
And this is my code:
Code: Select all
<div style="width:310px; height:16px;">
                
<div style="float:left; width:310px;" align="left"><a id="login" href="javascript:closeDivArea('cont','login');">CLOSE</a></div>

</div>

<div id="cont" style="width:310px;" align="center">
        
"MY DIV BOX CONTENT"

</div>
Sorry for my english and thanks in advance anyone give me a little help...

Last edited by Maska; Sep 29th, 2007 at 15:12.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Sep 29th, 2007, 23:55
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Show&Hide Div Box

Okay you could have a function that toggles the area, this one will completely remove the space from where the div was.

Code: Select all
<script type="text/javascript">

function toggle(obj, lnk)
{
    obj = document.getElementById(obj);
    
    if (obj.style.display != 'block')
    {
		obj.style.display = 'block';
		lnk.innerHTML = 'Close';
	} else {
		obj.style.display = 'none';
		lnk.innerHTML = 'Open';
	}
}
</script>
<a href="javascript:void()" onclick="toggle('cont', this)">Open</a>

<div id="cont" style="display:none;">

Hello Div COntent

</div>
It seems like your code is doing a lot more work than it has to.

Cheers
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Sep 30th, 2007, 01:41
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Show&Hide Div Box

I tried doing a code like this previously,
but mine was pretty bad.
May use this thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Sep 30th, 2007, 08:37
Junior Member
Join Date: Sep 2007
Location: Romania
Age: 38
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Re: Show&Hide Div Box

Quote:
Originally Posted by Rakuli View Post
Hello Div Content
Very nice answer, very useful and very funny too!
Works perfectly!
Thanks again Rakuli; like usually, you solve my problem successfully and professionally too...
I am verry happy becouse i find this professional forum with so kind members too, so i put a link on my site, like my gratefully, on www.jocurigratuit.ro (it is a games site). I don`t know how much it will help but this forum must have more visitors becose it deserve
If the admin have a small banner 88x31 px. i will add also.
Thanks again Rakuli!

Last edited by Maska; Oct 1st, 2007 at 11:06.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Oct 1st, 2007, 10:47
Junior Member
Join Date: Sep 2007
Location: Romania
Age: 38
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Re: Show&Hide Div Box

It is posible to use two java scripts like this one, on the same page, in the differend locations without confuse the elements script?
I try to use this js. two times in the same page in differend locations and the functions works conflicting, simultaneous.
Thanks anyone give me the right solution!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Oct 1st, 2007, 10:57
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Show&Hide Div Box

This should work without any issue at all.

You just need to specify the name of the div you want to toggle and use the 'this' keyword to pass the reference to the link.

ie.

<a href="javascript:void()" onclick="toggle('div1', this)">Toggle Div1</a>

<a href="javascript:void()" onclick="toggle('div2', this)">Toggle Div 2</a>

etc..
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Oct 1st, 2007, 11:04
Junior Member
Join Date: Sep 2007
Location: Romania
Age: 38
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Show&Hide Div Box

Quote:
Originally Posted by Rakuli View Post
This should work without any issue at all.
My best friend forever!
I feel must pay you for every answer i get from you, insomuch that i like your fast answer!
Thank you again Rakuli!

Last edited by Maska; Oct 1st, 2007 at 15:30.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Thread Tools

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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show/Hide Div + change image=HELP Webill JavaScript Forum 3 May 11th, 2008 15:08
CSS Show Hide with JS abis123 JavaScript Forum 4 Dec 13th, 2007 05:39
Show/Hide JS pa007 JavaScript Forum 0 Apr 6th, 2007 19:18
Show and Hide Text - how do I do that? Love2Java JavaScript Forum 1 Mar 29th, 2007 00:23
Show/Hide Div Help Trebz JavaScript Forum 2 Feb 21st, 2006 22:37


All times are GMT. The time now is 19:05.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved