Calendar help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Treetop

    Calendar help

    I am creating a calendar with JavaScript. I want to be able to put
    date and time in an array and have a calendar display properly with 7
    columns. I am stuck at this point. Any help would be appreciated. I
    hope I formatted it properly for this group.



    var month="October 2003";

    var ct = 0;

    var dt=new Array();
    dt[1]=new Array("1,5:15-8");
    dt[2]=new Array("2,5-8");
    dt[3]=new Array("3,5-8");
    dt[4]=new Array("4,1-4:45");
    dt[5]=new Array("5,1-3");
    dt[6]=new Array("6,4:45-6:45");
    dt[7]=new Array("7,4:45-6:45");
    dt[8]=new Array("8,none") ;
    dt[9]=new Array("9,4:45-6:45");
    dt[10]=new Array("10,3:30-6:30");
    dt[11]=new Array("11,1-3");
    dt[12]=new Array("12,1-3");
    dt[13]=new Array("13,4:45-6:45");
    dt[14]=new Array("14,4:45-6:45");
    dt[15]=new Array("15,none" );
    dt[16]=new Array("16,none" );
    dt[17]=new Array("17,4:45-6:45");
    dt[18]=new Array("18,NOICE ");
    dt[19]=new Array("19,1-3");
    dt[20]=new Array("20,4:45-6:45");
    dt[21]=new Array("21,4:45-6:45");
    dt[22]=new Array("22,none" );
    dt[23]=new Array("23,none" );
    dt[24]=new Array("24,12-2");
    dt[25]=new Array("25,1-3");
    dt[26]=new Array("26,1-3");
    dt[27]=new Array("27,4:30-6:45");
    dt[28]=new Array("28,4:30-6:45");
    dt[29]=new Array("29,NO ICE");
    dt[30]=new Array("30,NO ICE");
    dt[31]=new Array("31,NO ICE");


    document.write( '<center><tabl e border width=530',
    ' bgcolor="ffffff ">');
    document.write( '<tr><td colspan=7><h1 align=center>'
    + month + ' Public Skating Times<\/h1><\/td><\/tr>');

    document.write( '<tr align=center>') ;
    document.write( '<td><b>Sunday< \/b><\/td>');
    document.write( '<td><b>Monday< \/b><\/td>');
    document.write( '<td><b>Tuesday <\/b><\/td>');
    document.write( '<td><b>Wednesd ay<\/b><\/td>');
    document.write( '<td><b>Thursda y<\/b><\/td>');
    document.write( '<td><b>Friday< \/b><\/td>');
    document.write( '<td><b>Saturda y<\/b><\/td><\/tr>');

    for (var i=dt.length-1;i>=0;i--)
    {
    if (ct <= 7) {
    if (ct = 0) {
    document.write( '<td valign=top colspan=' +
    ct + '> + dt[i][0] + '<br>' + dt[i][1] +
    '<\/td>');
    }
    document.write( '<td valign=top>' + dt[i][0] +
    '<br>' + dt[i][1] + '<\/td>');
    ct = ct + 1
    if (ct = 7) {
    document.write( '<\/tr><tr valign=top align=right>');
    ct = 1;
    }
    }


    document.write( '<\/tr><\/table><br><b>NO TE:',
    'All times are PM unless noted.<\/b><\/center>');


  • Dr John Stockton

    #2
    Re: Calendar help

    JRS: In article <aad5ec0a4038f8 a9b2720f025f48d b70@news.terane ws.com>,
    seen in news:comp.lang. javascript, Treetop <treetop@netfro nt.net> posted
    at Wed, 8 Oct 2003 16:28:04 :-[color=blue]
    >I am creating a calendar with JavaScript. I want to be able to put
    >date and time in an array and have a calendar display properly with 7
    >columns. I am stuck at this point. Any help would be appreciated. I
    >hope I formatted it properly for this group.
    >
    >
    >
    >var month="October 2003";
    >
    >var ct = 0;
    >
    >var dt=new Array();
    >dt[1]=new Array("1,5:15-8");
    >dt[2]=new Array("2,5-8");
    >dt[3]=new Array("3,5-8");
    >dt[4]=new Array("4,1-4:45");[/color]

    There is no real need to store day-of-month in an array indexed by day-
    of-month.

    This line is wrong :
    ct + '> + dt[i][0] + '<br>' + dt[i][1] + '

    and in that region you need to count and adjust your } to match { - add
    one after ct = 1; ?

    i>=0 should be i>0 .

    That at least gets you a Table showing.

    if ( = ) should be if ( == ), twice.

    That gets a multi-column table.

    In the many new Array lines, put the first " after the ' .


    Your move.


    I think you write too much code at once, before testing. since you can
    view pages locally, you should test after every step


    You could start with the code of <URL:http://www.merlyn.demon.co.uk/js-
    date6.htm#DP> and replace LZ(Q) by dt[Q], using that array dt. Titivate
    the layout; you'll need to pad the entries to constant width, and/or
    perhaps change the buttons to table elements.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

    Comment

    • Treetop

      #3
      Re: Calendar help

      I got the Calendar working and is at


      in case anyone wanted to see it. The JavaScript code is at



      In order to diplay the dates in the correct order I had to change the
      array from

      dt[31]=new Array("31","NO ICE");
      to
      dt[1]=new Array("31","NO ICE");

      Instead of the date corrisponding to the dt number (don't know proper
      term) I had to reverse the order for it to display properly.

      I have a question on this. I can comment out the line dt[1... if I
      don't need the date. Will this mess up how it displays on non
      Netscape / IE browsers? For example If I have a month with only 30
      days I can comment out the line with the 31st date in it, however the
      dt number (don't know proper term) of 1 will not be displayed. The
      Array will start with 2 instead of 1. I hope my question makes sense.


      Comment

      • Dr John Stockton

        #4
        Re: Calendar help

        JRS: In article <cf3a6353136872 f5adefd76f9a561 282@news.terane ws.com>,
        seen in news:comp.lang. javascript, Treetop <treetop@netfro nt.net> posted
        at Thu, 9 Oct 2003 16:55:13 :-[color=blue]
        >
        >I have a question on this. I can comment out the line dt[1... if I
        >don't need the date. Will this mess up how it displays on non
        >Netscape / IE browsers? For example If I have a month with only 30
        >days I can comment out the line with the 31st date in it, however the
        >dt number (don't know proper term) of 1 will not be displayed. The
        >Array will start with 2 instead of 1. I hope my question makes sense.[/color]

        An Array can have "missing" elements; AFAICS, an Array is basically an
        Object with some added methods and a feeling of kinship with the
        linearly-stored arrays of traditional languages. You will then need to
        allow for the possibility of looking at an element which is undefined.
        But var U gives a U which is equally undefined.

        One can use an Object instead, with data like :

        Events =
        { Y2003:{M10:{D26 :"Summer Time Off"}, M03:{D30:'Summe r Time On'}},
        Y2004:{M04:{D11 :"Easter Sunday"}} }

        Yearly =
        { M04:{D01:"All Fools Day"}, M12:{D25:'Chris tmas Day'},
        M10:{D21:"Trafa lgar Day"}, M06:{D18:'Water loo Day'} }

        <URL:http://www.merlyn.demo n.co.uk/js-date6.htm#EP>, still changing, is
        an Event Picker using such; it does not yet? allow for more than one
        entry per day in either Object.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Calendar help

          Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
          [color=blue]
          > An Array can have "missing" elements; AFAICS, an Array is basically an
          > Object with some added methods and a feeling of kinship with the
          > linearly-stored arrays of traditional languages.[/color]

          Indeed. A Javascript array is a Javascript object with extra
          functionality. There are some extra methods in Array.prototype , but
          they can all be used on other objects too if you want it.

          The one thing that makes arrays unique is the length property, which
          is linked to the properties with names that can be represented as 32
          bit integers.

          As an invariant, the value of the length property must be larger than
          all integer properties of the array. If you create a new integer named
          property that is larger than the length property, the length property
          is increased. If you decrease the length property, some integer named
          properties are deleted. That is all that makes an array special.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Dr John Stockton

            #6
            Re: Calendar help

            JRS: In article <wubd7vvo.fsf@h otpop.com>, seen in
            news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
            posted at Fri, 10 Oct 2003 02:56:59 :-[color=blue]
            >Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
            >[color=green]
            >> An Array can have "missing" elements; AFAICS, an Array is basically an
            >> Object with some added methods and a feeling of kinship with the
            >> linearly-stored arrays of traditional languages.[/color]
            >
            >Indeed. A Javascript array is a Javascript object with extra
            >functionalit y. There are some extra methods in Array.prototype , but
            >they can all be used on other objects too if you want it.[/color]

            I don't follow - does that, for example, apply to the Array method
            reverse, which seems inapplicable to Objects with general names
            "inside"?

            [color=blue]
            >The one thing that makes arrays unique is the length property[/color]
            ...


            <URL:http://www.merlyn.demo n.co.uk/js-date6.htm#EP>, still changing, now
            handles multiple entries per day.

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
            <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
            <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: Calendar help

              Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
              [color=blue]
              > I don't follow - does that, for example, apply to the Array method
              > reverse, which seems inapplicable to Objects with general names
              > "inside"?[/color]

              It applies to any object with a property called "length" and zero or
              more properties whose names are representable as 32-bit integers.

              var o = {"0":"a","2":"b ","3":"c","10": "z",length: 4};
              Array.prototype .reverse.call(o );
              alert(Array.pro totype.join.cal l(o,"/") + " : " + o[10]);

              By design, most array properties are general, and can be applied to
              any object. The only assume the existence of a length property, and
              they operate on the integer numbered properties smaller than the
              length.

              That means that they are applicaply to arrays, HTML collections
              (except that they are not mutable), etc. They don't touch the
              non-integer properties.

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              Working...