Solved

Javascript Hide dive based on date range

Posted on 2013-01-24
5
419 Views
Last Modified: 2013-01-25
I need to show and hide some divs depending on a date range

for example if the current date is between 1/1/2013 and 1/7/2013 I want so show the first notice and hide the rest. Note I cannot use Jquery.

<html>
   <head>
      <div id="hideshow1">
         <h23 />
         <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 1</marquee>
         </span>
      </div>
      <div id="hideshow2">
         <h23 />
         <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 2</marquee>
         </span>
      </div>
      <div id="hideshow3">
         <h23 />
         <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 3</marquee>
         </span>
      </div>
      <div id="hideshow4">
         <h23 />
         <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 4
            </marquee>
         </span>
      </div>
      <div id="hideshow5">
         <h23 />
         <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 5
            </marquee>
         </span>
      </div>
</html>
0
Comment
Question by:JonMny
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38815907
The code you posted is nowhere near being an HTML page.

I don't know what <h23 /> is supposed to be.

The marquee tag is non-standard, and has never been part of any standard.  Some browsers support it, but there is no guarantee they will continue to do so.  It should not be used in any context, and creates both usability and accessibility issues.

Th page is malformed with no body, and unclosed head and missing required tags.

As for hiding and showing based on the date range, you either set it when you generate the page on the server, or you use scripting on the page to set either the visibility or display properties in the CSS.

Cd&
0
 
LVL 9

Author Comment

by:JonMny
ID: 38815918
This is just a sample of what the html looks like. Only has to work in IE
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38815967
Without some real working code for reference, there is not much that can happen.  All I've seen at this point is a bunch of invalid junk that looks like it was done by a ten year old.

Cd&
0
 
LVL 9

Author Comment

by:JonMny
ID: 38816061
The HTML works just fine for me.  

Here if this helps

<!DOCTYPE html>
<html>
<body>
     <div id="hideshow1">
            <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 1</marquee>
         </span>
      </div>
      <div id="hideshow2">
          <span style="color: #006400">
            <marquee behavior="alternate" direction="left">Notice 2</marquee>
         </span>
      </div>
</body>
</html>
0
 
LVL 9

Accepted Solution

by:
Sar1973 earned 500 total points
ID: 38818299
You need a script like:
function ShowDivs() {
	var myDate = new Date(); 
	var myDiv1 = document.getElementById("hideshow1");
	var myDiv2 = document.getElementById("hideshow2");
	if (myDate >"1/1/2013" && myDate<"1/7/2013") {
		myDiv1 .style.display="inline";
		myDiv2 .style.display="inline";
	} else {
		myDiv1 .style.display="none";
		myDiv2 .style.display="none";
	}
}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now