Solved

Javascript Hide dive based on date range

Posted on 2013-01-24
5
424 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Text too large in Chrome 17 61
null, truthy, falsey confusion 25 30
A responsive image gallery using flexbox 6 19
aria difference 2 14
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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