0

I created a sweepstakes official rules pop-up that automatically updates the date when the month changes. It works perfectly, except in IE, ugh! So I am trying to make java script changes in a span tag for just the dynamic content, but I hit a snag. I know I need to use innerHTML and configure with an id, but I am not sure how to implement it. here is my all-java generated pop-up: http://images.zales.com/images/CMSImages/angelaspeed/test/rw_sweeps.html (remember it doesn't work in IE).

Secondly, I have not found an effective way to generate the last day of the month to use in my inline code, therefore you will see "last day of" month + year used. If you have a solution, Please let me know.

Thanks Gurus, Love Ms. Novice

  • What version of IE and does the console show any error(s)? – couzzi Mar 22 '13 at 21:27
  • I am on a mac and am required to support 7+. I have crossover and it shows up, but my colleagues on PC say it does not render. – Angela Speed Mar 22 '13 at 21:32
  • I ran your URL through [http://netrenderer.com/index.php](http://netrenderer.com/index.php) and it I was able to see the dates in red for versions 6-10 of IE. Did they say it was blank? Or did it render incorrectly? – couzzi Mar 22 '13 at 21:36
  • they said all they could see was the non-javascript generated text (starting with Colorado Disclosure Box). – Angela Speed Mar 22 '13 at 21:42
  • OH, so the issue is not specifically with the `date` portion, everything in `document.write` is failing for them. I know this sounds ridiculous, but is there any chance they have Javascript turned off? – couzzi Mar 22 '13 at 21:46
  • That is possible, but I need to have this viewable for the general public and can't tell them to "enable Java Script to view" Any help available on my second question?? – Angela Speed Mar 22 '13 at 22:17
  • [http://stackoverflow.com/questions/222309/calculate-last-day-of-month-in-javascript](http://stackoverflow.com/questions/222309/calculate-last-day-of-month-in-javascript) – couzzi Mar 22 '13 at 22:25
  • AND if I need next month's first mid or last date? Shouldn't I bea able to use this? lastdate = new Date(y, (m + 1,) 0).getDate(); changing the 0 to the 1, 15 or 0? I think I'm over simplifying. – Angela Speed Mar 25 '13 at 15:50
  • that specific code creates a conflict and renders none of my java generated text in any browser (even just adding the variable, with my scripts). to get around it, I defined separate month, day and year elements and put them together like: + months[month_value] + " 1, " + year_value + but still would rather generate the number only of the last day of the month instead of having to say, "the last day of " + months[month_value] + ", " + year_value + – Angela Speed Mar 25 '13 at 16:50

2 Answers2

1

new Date(y, m, 0).getDate() returns the date of the last day of the month, where m is a an integer between 1 and 12 and y is the 4 digit year.

kennebec
  • 102,654
  • 32
  • 106
  • 127
0
var today = new Date(),

    firstOfMonth = new Date(today.getFullYear(), today.getMonth(), 1),
    midMonth     = new Date(today.getFullYear(), today.getMonth(), 15),
    lastOfMonth  = new Date(today.getFullYear(), today.getMonth()+1, 0);

   document.write(firstOfMonth + "<br/>" + midMonth + "<br/>" + lastOfMonth);

In response to comments from OP above.

couzzi
  • 6,316
  • 3
  • 24
  • 40