JavaScript output based on date
<p>Updated answer to my own question.</p>

<p>I have updated my own code with a more robust one.</p>

<pre><code>// JavaScript Document
var today = new Date;
var Event0 = new Date;
Event0.setDate(1);
Event0.setMonth(0); // January = 0
Event0.setFullYear(2011); 
var Event1 = new Date;
Event1.setDate(1);
Event1.setMonth(1); // January = 0
Event1.setFullYear(2011); 
var Event2 = new Date;
Event2.setDate(1);
Event2.setMonth(2); // January = 0
Event2.setFullYear(2011); 
var Event3 = new Date;
Event3.setDate(1);
Event3.setMonth(3); // January = 0
Event3.setFullYear(2011); 
var Event999 = new Date;
Event999.setDate(1);
Event999.setMonth(0); // January = 0
Event999.setFullYear(2012); 
var ev = "&lt;strong&gt;Error\ !&lt;\/strong&gt;&lt;br\/&gt;Could not find Event Feed"
var ev0 = "&lt;strong&gt;Error\ !&lt;\/strong&gt;&lt;br\/&gt;Please check your computers date settings&lt;br\/&gt;Year set before 2011"
var ev1 = "Event 1"
var ev2 = "Event 2"
var ev3 = "Event 3"
var ev999 = "&lt;strong&gt;Error\ !&lt;\/strong&gt;&lt;br\/&gt;Please check your computers date settings&lt;br\/&gt;Year set after 2012"
if (today &lt;= Event0) var ev = ev0
if (today &gt;= Event1) var ev = ev1
if (today &gt;= Event2) var ev = ev2
if (today &gt;= Event3) var ev = ev3
if (today &gt;= Event999) var ev = ev999
</code></pre>

<hr>

<p>-- OLD QUESTION --</p>

<p>I am trying to have the following code set an output.</p>

<ul>
<li>If Event1 date is = to or greater
then today's date display ev1.</li>
<li>If Event2 date is = to or greater
then today's date stop displaying ev1
and show ev2</li>
<li>If Event3 date is = to or greater
then today's date stop displaying ev2
and show ev3</li>
</ul>

<p>Q: Is there a better way of doing this or is my code OK to produce the outcome I am looking for. I am new to JavaScript so I hope I have done this right.</p>

<p>--- code in ext JS file ---</p>

<pre><code>&lt;script type="text/javascript"&gt;
var today = new Date;
var Event1 = new Date;
Event1.setDate(1);
Event1.setMonth(0); // January = 0
Event1.setFullYear(2011); 
var Event2 = new Date;
Event2.setDate(1);
Event2.setMonth(1); // January = 0
Event2.setFullYear(2011); 
var Event3 = new Date;
Event3.setDate(1);
Event3.setMonth(2); // January = 0
Event3.setFullYear(2011); 
var ev1 = "Event 1 at location A"
var ev2 = "Event 2 at location B"
var ev3 = "Event 3 at location C"
if (today &gt;= Event1) var ev = ev1
if (today &gt;= Event2) var ev = ev2
if (today &gt;= Event3) var ev = ev3
&lt;/script&gt;
</code></pre>

<p>--- code on page ---</p>

<pre><code>&lt;script language="JavaScript"&gt;&lt;!--
document.write(ev);
//--&gt;
&lt;/script&gt;
</code></pre>

<p>Thank you in advance</p>
