PDA

View Full Version : creating archive list - giving "undefined" before list


acc
02-28-2005, 07:04 PM
basic function of this script is
1. to create a "year" listing
2. from selected "year", the date and title of each press release will be displayed, which will then show the full press release on a pop-up

i got all these working, but no clue as to why an "undefined" shows in the beginning of the list

here's the scrips:

var tmpValue = (5); // default value shows archive for current year


//------------------------------------------------------------------------------------------------------------------------------
// write year links on "year" layer
function writeYear()
{
var cc;

cc=("");
i = 4
while (i <= 5) {
if (i == 4){
cc+=("<span><a href=\"javascript:void(0)\" onClick=\"javascript:getValue04();javascript:writeArchive(Press);\">");
cc+= ("200" + i);
cc+=("</a></span>");
cc+=(" ");
}
else if (i == 5){
cc+=("<span><a href=\"javascript:void(0)\" onClick=\"javascript:getValue05();javascript:writeArchive(Press);\">");
cc+= ("200" + i);
cc+=("</a></span>");
cc+=(" ");
}
i++
}

document.getElementById("year").innerHTML = cc;
top.document.title = ("Press Releases");
}


//------------------------------------------------------------------------------------------------------------------------------
//gives the value to variable tmpValue depending on year chosen
function getValue04(){
tmpValue = (4);
}

function getValue05(){
tmpValue = (5);
}

//------------------------------------------------------------------------------------------------------------------------------
//create archive links for a specific year on "archive" div layer
function writeArchive(Press)
{
var archive; // holds all data to be displayed
var month; // month value
var day; // day value
var yy; // holds the year value

if (tmpValue == 4){
yy = (2004);
}
else if (tmpValue == 5){
yy = (2005);
}

// loops to display month, day and some content
for (month in Press[yy]){

for (day in Press[yy][month]){

//writes the date and links it
//archive+=("<a id=\""+yy+"_"+month+"_"+day+"\" href=\"javascript:void(0)\" onclick=\"showPress(this.id)\">");
archive+=("<a href=\"javascript:void(0)\" onclick=\"javascript:NewWindow('"+yy+"/"+month+""+day+".html','new','700','440','yes')\" >");
archive+=(month + " " + day);
archive+=("</a><br>");

//write some content from specific date
archive+=(Press[yy][month][day].substring(0) + "...");
archive+=("<br><br>");
}
}

document.getElementById("archive").innerHTML = archive;
}

glenngv
03-01-2005, 04:37 AM
You need to initialize the archive variable to empty.

var archive=""; // holds all data to be displayed

acc
03-01-2005, 01:59 PM
oh my...i knew it was something simple...thanks a lot glenngv, now it's working nicely!