Solved

Javascript Hide dive based on date range

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 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