Return to iWEBTOOL

Go Back   iWEBTOOL Talk > The Web and your Website > Programming > HTML > JavaScript
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
Welcome to iWEBTOOL Talk, where you talk about webmaster-related stuff.
 
Discuss topics which interest you.
With over thousands of threads (topics), we're sure you'll find something that'll interest you.
Ask for help whenever you need it.
We have thousands of members who are available to help you if you need it.
It's absolutely FREE!

 1  Register           2  Browse the board           3  Discuss whatever may interest you!
 


Closed Thread
 
Thread Tools Search this Thread Display Modes
Old 02-21-2006, 12:56 PM   #1
MrLeN
Member
 
MrLeN's Avatar
 
Join Date: Feb 2006
Location: Melbourne, AU
Posts: 41
MrLeN will become famous soon enough
Default Show - Hide

In this following script, box 2 opens of you clock box 2. Box 1 opens of you click box 1. But if you click box 1 and 2 or box 2 and 1, they are both open at the same time. I don't want that. I want it so that of box 2 is open and you click box 1, box 2 closes, and vice versa.



Basically, I just need to have one box open at a time.



Does anyone know how to edit this file so that it works like that?



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>

<script>
function HideandUNhideObj(ThisObj){
if((nav = document.getElementById(ThisObj)).className == 'myHide')
nav.className = 'myShow';
else
nav.className = 'myHide';
}
</script>
<style>
.myHide {
display: none;
}

</style>
</head>

<body>
<a href="#" onclick="HideandUNhideObj('box1');">Box 1</a> |
<a href="#" onclick="HideandUNhideObj('box2');">Box 2</a>
<div id="box1" class="myHide">
Box 1<br />
</div>
<div id="box2" class="myHide">
Box 2<br />
</div>
</body>
</html>

MrLeN
__________________
News and Entertainment
MrLeN is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
SEO Checklist
Get yourself better ranking with
our "Do-it-Yourself" SEO Checklist.
Click Here
Old 02-21-2006, 03:49 PM   #2
kenni
Registered Member
 
kenni's Avatar
 
Join Date: Dec 2005
Posts: 1,543
kenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to beholdkenni is a splendid one to behold
Default Re: Show - Hide

Replace your <script></script> with the following;

HTML Code:
<script> function HideandUNhideObj(ThisObj){ if (ThisObj !== "box1") { document.getElementById('box1').className = 'myHide'; } if (ThisObj !== "box2") { document.getElementById('box2').className = 'myHide'; } if (document.getElementById(ThisObj).className == 'myHide') { document.getElementById(ThisObj).className = 'myShow'; } else { document.getElementById(ThisObj).className = 'myHide'; } } </script>
__________________
Wanna thank someone? Give 'em a rep. More info.
kenni is offline  
Old 03-15-2006, 08:38 PM   #3
Zack
Junior Guru
 
Zack's Avatar
 
Join Date: Dec 2005
Location: North Carolina
Posts: 759
Zack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to beholdZack is a splendid one to behold
Send a message via MSN to Zack
Default Re: Show - Hide

That or I use the following:
HTML Code:
<html> <head> <script type="text/javascript"> var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off) var collapseprevious="no" //Collapse previously open content when opening present? (yes/no) var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif"> var expandsymbol='+ ' //HTML for expand symbol. if (document.getElementById){ document.write('<style type="text/css">') document.write('.switchcontent{display:none;}') document.write('</style>') } function getElementbyClass(rootobj, classname){ var temparray=new Array() var inc=0 var rootlength=rootobj.length for (i=0; i<rootlength; i++){ if (rootobj[i].className==classname) temparray[inc++]=rootobj[i] } return temparray } function sweeptoggle(ec){ var thestate=(ec=="expand")? "block" : "none" var inc=0 while (ccollect[inc]){ ccollect[inc].style.display=thestate inc++ } revivestatus() } function contractcontent(omit){ var inc=0 while (ccollect[inc]){ if (ccollect[inc].id!=omit) ccollect[inc].style.display="none" inc++ } } function expandcontent(curobj, cid){ var spantags=curobj.getElementsByTagName("SPAN") var showstateobj=getElementbyClass(spantags, "showstate") if (ccollect.length>0){ if (collapseprevious=="yes") contractcontent(cid) document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none" if (showstateobj.length>0){ //if "showstate" span exists in header if (collapseprevious=="no") showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol else revivestatus() } } } function revivecontent(){ contractcontent("omitnothing") selectedItem=getselectedItem() selectedComponents=selectedItem.split("|") for (i=0; i<selectedComponents.length-1; i++) document.getElementById(selectedComponents[i]).style.display="block" } function revivestatus(){ var inc=0 while (statecollect[inc]){ if (ccollect[inc].style.display=="block") statecollect[inc].innerHTML=contractsymbol else statecollect[inc].innerHTML=expandsymbol inc++ } } function get_cookie(Name) { var search = Name + "=" var returnvalue = ""; if (document.cookie.length > 0) { offset = document.cookie.indexOf(search) if (offset != -1) { offset += search.length end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; returnvalue=unescape(document.cookie.substring(offset, end)) } } return returnvalue; } function getselectedItem(){ if (get_cookie(window.location.pathname) != ""){ selectedItem=get_cookie(window.location.pathname) return selectedItem } else return "" } function saveswitchstate(){ var inc=0, selectedItem="" while (ccollect[inc]){ if (ccollect[inc].style.display=="block") selectedItem+=ccollect[inc].id+"|" inc++ } document.cookie=window.location.pathname+"="+selectedItem } function do_onload(){ uniqueidn=window.location.pathname+"firsttimeload" var alltags=document.all? document.all : document.getElementsByTagName("*") ccollect=getElementbyClass(alltags, "switchcontent") statecollect=getElementbyClass(alltags, "showstate") if (enablepersist=="on" && ccollect.length>0){ document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load if (!firsttimeload) revivecontent() } if (ccollect.length>0 && statecollect.length>0) revivestatus() } if (window.addEventListener) window.addEventListener("load", do_onload, false) else if (window.attachEvent) window.attachEvent("onload", do_onload) else if (document.getElementById) window.onload=do_onload if (enablepersist=="on" && document.getElementById) window.onunload=saveswitchstate </script> </head> <body> <font onClick="expandcontent(this, 'content1')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>box 1</font></div> <div id="content1" class="switchcontent">your content <font onClick="expandcontent(this, 'content2')" style="cursor:hand; cursor:pointer"><span class="showstate"></span>box 2</font></div> <div id="content2" class="switchcontent">your content

Hope this helps!
HTMLGuy
__________________
yaxal releases '07
Zack is offline  
 
This is an Ad Revenue Sharing forum Place your advert here
Webmaster Tools Webmaster Tools Click Here
Closed Thread

(Threads which have no activity for more than 30 days are automatically closed.)



Quick Reply
Message:

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Ur Site Albert Tai Websites for Sale 1 11-04-2006 04:45 PM
Better links: Do not hide reciprocal link site 123_free_links Links for Sale 0 05-19-2006 04:33 AM
Exchange links: reciprocal link page shall not hide 123_free_links Links for Sale 0 05-19-2006 04:27 AM
SHOW-OFF: my domains Z_T Domain Name 2 12-27-2005 12:54 AM


All times are GMT. The time now is 03:57 AM.


Powered by vBulletin v3.6.7 © 2008, Jelsoft Enterprises Ltd. SEO by vBSEO © 2006, Crawlability, Inc.