Solved

Javascript Hide dive based on date range

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

706 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

12 Experts available now in Live!

Get 1:1 Help Now