Show only Current Events

[Total: 0    Average: 0/5]

This will show events in a table that are active.

Body Code:

<script>


/*
 * This defines an array to hold all the "event" objects as well as the object definition
 */
var _all_Events = new Array();
function _Event_Object(_start,_end,_text,_link)
{
   this.START = _start;
   this.END   = _end;
   this.TEXT  = _text;
   this.LINK  = _link;
   _all_Events[_all_Events.length?_all_Events.length:0]=this;
}
_Event_Object.prototype.Start_Date_Is = function() {return(this.START);}
_Event_Object.prototype.End_Date_Is   = function() {return(this.END  );}
_Event_Object.prototype.Text_Is       = function() {return(this.TEXT );}
_Event_Object.prototype.Link_Is       = function() {return(this.LINK );}
/*
 * END of CONSTRUCT
 */

var _today= new Date();
var _todayMonth=_today.getMonth()+1;
var _todayDate =_today.getDate();
var _todayYear = _today.getFullYear()<2000?1900+_today.getFullYear():_today.getFullYear();
function list_events()
{
   var EVENT_FOUND=false; /* used to detect events printed */
   var _o ='';
       _o+='<CENTER>Today's Date is: ';
       _o+=_todayMonth;
       _o+='/';
       _o+=_todayDate;
       _o+='/';
       _o+=_todayYear;
       _o+='</CENTER>';
       _o+='<table align=center>';
       _o+='<tr>';
       _o+='<td>START DATE</td>';
       _o+='<td>END DATE</td>';
       _o+='<td>TEXT DATA</td>';
       _o+='</tr>';
   for(var i=0;i<_all_Events.length;i++)
   {
       /*
        * Only print out dates that are active
        */
       if(dateActive(_all_Events[i].Start_Date_Is(),_all_Events[i].End_Date_Is()))
       {
         EVENT_FOUND=true;
         _o+='<tr>';
         _o+='<td>'+_all_Events[i].Start_Date_Is()+'</td>';
         _o+='<td>'+_all_Events[i].End_Date_Is()+'</td>';
         _o+='<td>';
         if(_all_Events[i].Link_Is()) _o+='<a href="'+_all_Events[i].Link_Is()+'">';
         _o+=_all_Events[i].Text_Is();
         if(_all_Events[i].Link_Is()) _o+='</a>';
         _o+='</td>';
         _o+='</tr>';
       }
   }
   if(!EVENT_FOUND)
   {
       _o+='<tr><td colspan=3 align=center>No Active Events Found</td></tr>';
   }
       _o+='</table>';
   document.write(_o);
}

function dateActive(_start,_end)
{
   var _return = true;
   var _m1,_d1,_y1;
     _m1=_start.split("/")[0];
     _d1=_start.split("/")[1];
     _y1=_start.split("/")[2];
   var _m2,_d2,_y2;
     _m2=_end.split("/")[0];
     _d2=_end.split("/")[1];
     _y2=_end.split("/")[2];

   /* start dates that have not occurred */
   if(_y1 > _todayYear) return false;
   if(_y1 == _todayYear && _m1 > _todayMonth) return false;
   if(_y1 == _todayYear && _m1 == _todayMonth && _d1 > _todayDate) return false;

   /* end dates that have already past */
   if(_y2 < _todayYear) return false;
   if(_y2 == _todayYear && _m2 < _todayMonth) return false;
   if(_y2 == _todayYear && _m2 == _todayMonth && _d2 < _todayDate) return false;

   return (_return);
}

/******************************************************************/

/*
 * The "_Event_##" does not really matter - they can all be the same
 * The 4 parameters:
 *    1) Starting Date
 *    2) Ending Date
 *    3) Text To Show
 *    4) Optional Link Text goes to
 */
var _Event_01 = new _Event_Object("1/2/2001","1/2/2002","This is event 1 -active","http://www.js-examples.com/");
var _Event_02 = new _Event_Object("1/2/2001","3/2/2001","This is event 2 -past-month");
var _Event_03 = new _Event_Object("1/2/2001","9/2/2001","This is event 3 -active");
var _Event_04 = new _Event_Object("8/2/2001","9/2/2001","This is event 4 -future-month");
var _Event_05 = new _Event_Object("6/1/2001","6/30/2001","This is event 5 -active-day");
var _Event_05 = new _Event_Object("5/1/2001","5/30/2001","This is event 5 -past-month");
var _Event_06 = new _Event_Object("1/2/2000","8/2/2000","This is event 6 -past-year");
var _Event_07 = new _Event_Object("6/25/2001","6/25/2001","This is event 7 -today","http://www.js-examples.com/");
var _Event_08 = new _Event_Object("1/2/2001","1/2/2002","This is event 8","http://www.js-examples.com/");

var _Event_XX = new _Event_Object("1/2/2001","1/2/2002","active");
var _Event_XX = new _Event_Object("1/2/2002","1/2/2002","not started-year");
var _Event_XX = new _Event_Object("8/2/2001","1/2/2002","not started-month");
var _Event_XX = new _Event_Object("6/30/2001","1/2/2002","not started-day");

list_events();
</script>

Times Viewed: 4

Leave a Reply

Your email address will not be published. Required fields are marked *