Forum Moderators: open

Message Too Old, No Replies

Loop problem

for Loop problem

         

Javascript2005

10:52 pm on Jan 12, 2005 (gmt 0)

10+ Year Member



function printExam() {
line3 = "<h3>" + this.code + " " + this.modName + " " + "Exam Papers" + "<\/h3>\n"
line4 = "<ul style=\"list-style: none\">\n"
line5 = "<\/ul>\n"
for (var i = this.num; i > 0; i--) {
line7 = '<a href="www.google.com/' + this.modId + "/" + this.examDir
+ "/" + this.modId + "Exam"
+ dateToAbbrevSessOffset(new Date(), -i)
+ ".pdf" + "\">"
+ dateToSessionOffset(new Date(), -i)
+ " " + "PDF version" + "<\/a>\n"
}
outStr = line3 + line4 + line5 + line7
document.write (outStr)
}

function module(modId,code,modName,course,modDir,examDir, num) {

this.modId = modId;
this.code = code;
this.modName = modName;
this.course = course;
this.modDir = modDir;
this.examDir = examDir;
this.num = num;
this.printModule = printModule;
this.printExam = printExam;

}

I have got a problem with the for loop above. the page displays fine enough but heres the problem. if this.num = 2, it should display two hyperlinks. if this.num = 1, it would display one hyperlink etc.

when this.num = 1, it displays one link fine but when it is greater than 1, it can not seem to display more than one link.

what is wrong with the loop or coding? this Javascript code is driving me mad!

rocknbil

12:01 am on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And it's probably the last link in the list, right?

I'm guessing this:

line7 += '<a href="www.google.com/' + this.modId + "/" + this.examDir

Currently each iteration is overwriting the last one, this will concatenate it. :-)

EDIT: I bolded the += but it's not taking, note I've added a + before the =.

Javascript2005

12:59 am on Jan 13, 2005 (gmt 0)

10+ Year Member



correct, that is the only hyperlink within the list. I will test it in the morning.

Javascript2005

2:14 am on Jan 13, 2005 (gmt 0)

10+ Year Member



it works but i'm getting undefined displayed with the with links.

Javascript2005

9:40 am on Jan 13, 2005 (gmt 0)

10+ Year Member



i'm getting undefined in firefox and the links do not appear at all in IE. any other suggestions?

jbot

3:40 pm on Jan 13, 2005 (gmt 0)

10+ Year Member



this thread appears to have been sorted now: [codingforums.com ]

rocknbil

5:52 pm on Jan 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i'm getting undefined displayed with the with links

function printExam() {
var line3=line4=line5=line7=outStr='';

......

That would probably do it.