?
Solved

Hide and show DIV after set time

Posted on 2005-04-27
4
Medium Priority
?
383 Views
Last Modified: 2010-07-27
I found this solution here which hides the div tag after 7 seconds.  I would at the same time like to show another DIV tag after 7 seconds, so when one dissapears, the other will appear.

<script type="text/javascript"><!--
// hides anything btwn divs after a set period of time
var iNbSecondsBeforeHiding = 7;
var iNbHoursToHide = 24;
if (("&"+document.cookie).indexOf("&hidebanner=1") != -1)
  f_hideBanner();
else {
  setTimeout("f_hideBanner();",iNbSecondsBeforeHiding*1000)
  document.cookie = "hidebanner=1;expires="+(new Date((new Date()).getTime()+iNbHoursToHide*60*60*1000)).toGMTString();
}
function f_hideBanner() {
  if (document.getElementById)
    document.getElementById("myBanner").style.display = "none";
  else if (document.all)
    document.all["myBanner"].style.display = "none";
}
//--></script>
0
Comment
Question by:Insomniac_PhD
4 Comments
 
LVL 11

Expert Comment

by:SweatCoder
ID: 13881490
this is not an ASP question. you should post it in JavaScript or Web Development.
0
 
LVL 13

Assisted Solution

by:jrram
jrram earned 1000 total points
ID: 13881793
<script type="text/javascript"><!--
// shows anything btwn divs after a set period of time
var iNbSecondsBeforeShowing = 7;
var iNbHoursToShow = 24;
if (("&"+document.cookie).indexOf("&showbanner=1") != -1)
  f_showBanner();
else {
  setTimeout("f_showBanner();",iNbSecondsBeforeShowing*1000)
  document.cookie = "showbanner=1;expires="+(new Date((new Date()).getTime()+iNbHoursToHide*60*60*1000)).toGMTString();
}
function f_showBanner() {
  if (document.getElementById)
    document.getElementById("myBanner").style.display = "block";
  else if (document.all)
    document.all["myBanner"].style.display = "block";
}
//--></script>
0
 
LVL 10

Accepted Solution

by:
ThaSmartUno earned 1000 total points
ID: 13884968
well if its on a different timeout (like you want one to show at 7 secs and another to hide at 4 secs use  jrram's solution  but if you want to show the other div when you hide the banner use this:

function f_hideBanner() {
  if (document.getElementById){
    document.getElementById("myBanner").style.display = "none";
    document.getElementById("otherTag").style.display = "";
  }else if (document.all){
    document.all["myBanner"].style.display = "none";
    document.all["otherTag"].style.display = "";
  }
}

where otherTag is the tag of the div you want to show
0
 
LVL 3

Author Comment

by:Insomniac_PhD
ID: 13901990
jram, yours is very good.  Although I was looking for what ThaSmartUno posted, I will be using yours as well on another page I am building which kills 2 birds with 1 stone.  Thanks!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question