Hi, I'm trying to use a javascript for loop to write out links with titles from an array, that when clicked will execute a function I have written to pop open a new window, with info on the link clicked, this is the code I'm trying to use (this is inside the for loop), but I get the error in the title when I click on a link;

document.writeln('<a href="#"onClick=popUpInfo(' + subject[i] + ')>' + subject[i] + '</a>');

I think it's to do with using the escape sequence, because if I try to click a link when I don't put any parameter in the function like this:

document.writeln('<a href="#"onClick=popUpInfo()>' + subject[i] + '</a>');

It works (with the normal error for having no parameter) but I've tried lots of things with the escape sequence and I can't get it to work.
Help would be appreciated, thanks.

Member Avatar

My guess is that subject[i] is a string and you are treating it as a number or an object, instead of a string.

document.writeln('<a href="#" onclick="popUpInfo(\'' + subject[i] + '\')>' + subject[i] + '</a>');

Something like that should do it (didn't care to tested).

Nah that didn't help, subject is an object, I can't see what I'm doing wrong at all...

this will work:
document.writeln( "<a href='#' onClick='popUpInfo(" +subject[i]+ ")'>" +subject[i]+ "</a>" );

easy yeah?