By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,676 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,676 IT Pros & Developers. It's quick & easy.

Calendar help

P: n/a
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><table 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>Wednesday<\/b><\/td>');
document.write('<td><b>Thursday<\/b><\/td>');
document.write('<td><b>Friday<\/b><\/td>');
document.write('<td><b>Saturday<\/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>NOTE:',
'All times are PM unless noted.<\/b><\/center>');
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
JRS: In article <aa******************************@news.teranews.co m>,
seen in news:comp.lang.javascript, Treetop <tr*****@netfront.net> posted
at Wed, 8 Oct 2003 16:28:04 :-
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");


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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #2

P: n/a
I got the Calendar working and is at
http://www.tricityarena.com/skating_open.html

in case anyone wanted to see it. The JavaScript code is at
http://www.tricityarena.com/openskating.js
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.
Jul 20 '05 #3

P: n/a
JRS: In article <cf******************************@news.teranews.co m>,
seen in news:comp.lang.javascript, Treetop <tr*****@netfront.net> posted
at Thu, 9 Oct 2003 16:55:13 :-

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.


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:'Summer Time On'}},
Y2004:{M04:{D11:"Easter Sunday"}} }

Yearly =
{ M04:{D01:"All Fools Day"}, M12:{D25:'Christmas Day'},
M10:{D21:"Trafalgar Day"}, M06:{D18:'Waterloo Day'} }

<URL:http://www.merlyn.demon.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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
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.


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a
JRS: In article <wu**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Fri, 10 Oct 2003 02:56:59 :-
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
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.
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.


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

The one thing that makes arrays unique is the length property

...
<URL:http://www.merlyn.demon.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.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
I don't follow - does that, for example, apply to the Array method
reverse, which seems inapplicable to Objects with general names
"inside"?


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.prototype.join.call(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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.