Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript Hide dive based on date range

Posted on 2013-01-24
5
Medium Priority
?
429 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: blockā€¦
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

618 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