Javascript Array Problem

Hey guys,

I am trying to setup an archive calendar for a webcomic thruogh javascript. I've got the calendar part, but now I need to make it function. When a user clicks on certain dates, I want a popup window to open with a specific JPG being displayed within. ** If I can make the window open to the image's dimensions that wuld be incredible, but that is for a followup post.**

What I am trying to do is this:

Have an array and then set specific value = to a string value. Like this ...

var comics_array = new Array();
comics_array[5] = "dok1.jpg";

and then when I need to display it, it should like like:

popup('http://www.v7comics.com/comics/' + comics_array[5]);

Of course this isn't working and says "Object should be expected" on some line no where near of this code. Figures. Can anyone lend some insight or help? The next part of this process is coloring the calendar boxes that have values...

Thanks
[1016 byte] By [twistedfrog] at [2007-11-19 23:11:47]
# 1 Re: Javascript Array Problem
Of course this isn't working and says "Object should be expected" on some line no where near of this code. Figures. Typically if the error is on a line somewhere else, you'll need to post that code in order to receive any help. Make sure to provide the code for the popup function as well.
Dr. Script at 2007-11-8 0:40:31 >
# 2 Re: Javascript Array Problem
I wasn't too concerned with debugging that specific error on the random line.

My main question is "How can I accomplish what I am trying to accomplish?"

Is my idea completely whacked out? I believe that array[5] = "string" will not work in the syntax the way I have it. I think that is normally reserved for array["string"] = "string" to create associative arrays ... but then again I could be mistaken.

Anyone have an idea?

Thanks
twistedfrog at 2007-11-8 0:41:28 >
# 3 Re: Javascript Array Problem
and there is no popup() code ... popup() is a standard javascript function I thought.
twistedfrog at 2007-11-8 0:42:27 >
# 4 Re: Javascript Array Problem
and there is no popup() code ... popup() is a standard javascript function I thought.
No. There is no popup function in JavaScript. I have never heard of associative arrays in JavaScript before, only numerical.
PeejAvery at 2007-11-8 0:43:30 >
# 5 Re: Javascript Array Problem
Associative Arrays in javascript --> http://www.pageresource.com/jscript/jarray2.htm

I have two problems with this code ... #1 I can't get the height and width dimensions of window.open to work. Absolutely nothing.

Second I still cant get the arrays to work no matter what I try. It gives me the error "calendar"is undefined.

//Constructor
function calendar(id,d,p){
this.id = id;
this.dateObject = d;
this.pix = p;
this.write = writeCalendar;
this.length = getLength;
this.month = d.getMonth();
this.date = d.getDate();
this.day = d.getDay();
this.year = d.getFullYear();
this.getFormattedDate = getFormattedDate;
//get the first day of the month's day
d.setDate(1);
this.firstDay = d.getDay();
//then reset the date object to the correct date
d.setDate(this.date);
}

var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var comic_arr = new Array(1);
comic_arr[1] = "dok1.jpg";

function getFormattedDate(){
return days[this.day] + ', ' + months[this.month] + ' ' + this.date + ', ' + this.year;
//return this.month + '/' + this.date + '/' + this.year;
}

function writeCalendar(){
var calString = '<div id="calContainer">';
//write month and year at top of table
calString += '<table id="cal' + this.id + '" cellspacing="0" width="200" style="border:1px black solid;">';
//write the image comment out to hide images
//calString += '<tr><th colspan="7"><img src="' + this.pix[this.month].src + '"/></th></tr>';
//write the month
calString += '<tr><th colspan="7" class="month">' + months[this.month] + ', ' + this.year + '</th></tr>';
//write a row containing days of the week
calString += '<tr>';

for(i=0;i<days.length;i++){
calString += '<th class="dayHeader">' + days[i].substring(0,3) + '</th>';
}

//write the body of the calendar
calString += '<tr>';
//create 6 rows so that the calendar doesn't resize
for(j=0;j<42;j++){
var displayNum = (j-this.firstDay+1);
if(j<this.firstDay){
//write the leading empty cells
calString += '<td class="empty"> </td>';
}else if(displayNum==this.date){
calString += '<td id="' + this.id +'selected" class="date" onClick="javascript:changeDate(this,\'' + this.id + '\')">' + displayNum + '</td>';
}else if(displayNum > this.length()){
//Empty cells at bottom of calendar
calString += '<td> </td>';
}else{
//the rest of the numbered cells
calString += '<td id="" class="days" onClick="javascript:changeDate(this,\'' + this.id + '\')">' + displayNum + '</td>';
}
if(j%7==6){
calString += '</tr><tr>';
}
}
//close the last number row
calString += '</tr>';
//write the nav row
calString += '<tr>';
calString += '<td class="nav" style="text-decoration:underline;" onClick="changeMonth(-12,\'' + this.id + '\')"><</td>';
calString += '<td class="nav" onClick="changeMonth(-1,\'' + this.id + '\')"><</td>';
calString += '<td class="month" colspan="3"> </td>';
calString += '<td class="nav" onClick="changeMonth(1,\'' + this.id + '\')">></td>';
calString += '<td class="nav" style="text-decoration:underline;text-align:right;" onClick="changeMonth(12,\'' + this.id + '\')">></td>';
calString += '</tr>';

calString += '</table>';
calString += '</div>';
return calString;
}

function getLength(){
//thirty days has September...
switch(this.month){
case 1:
if((this.dateObject.getFullYear()%4==0&&this.dateObject.getFullYear()%100!=0)||this.dateObject.getFullYear()%400==0)
return 29; //leap year
else
return 28;
case 3:
return 30;
case 5:
return 30;
case 8:
return 30;
case 10:
return 30
default:
return 31;
}
}
function changeDate(td,cal){
cal = eval(cal);
document.getElementById(cal.id + "selected").className = "days";
document.getElementById(cal.id + "selected").id = "";
td.className = "date";
td.id = cal.id + "selected";
//set the calendar object to the new date
cal.dateObject.setDate(td.firstChild.nodeValue);
cal = new calendar(cal.id,cal.dateObject,cal.pix);
//here is where you could react to a date change - I'll just display the formatted date
//alert('poop on you');
window.open("http://www.v7comics.com/comics/dok1.jpg", height=323, width=600);
//window.open("http://www.v7comics.com/comics/" + comic_arr[1] + ", "Devil", status=1, height=323, width=600);

}

function changeMonth(mo,cal){
cal = eval(cal);
cal.dateObject.setMonth(cal.dateObject.getMonth() + mo);
cal = new calendar(cal.id,cal.dateObject,cal.pix);
cal.formattedDate = cal.getFormattedDate();
document.getElementById('calContainer').innerHTML = cal.write();

}

Any help at all would be greatly appriciated.
twistedfrog at 2007-11-8 0:44:29 >
# 6 Re: Javascript Array Problem
Does anyone have an idea on this?

I am most definitely stuck.
twistedfrog at 2007-11-8 0:45:27 >