0

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.

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Troy III
0

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).

0

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

0

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

easy yeah?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.