I'm having issues trying to pass a variable
basically I get information from an external xml document like this
What this does is create a list of the elements tagged "category" with a respective link to a javascript function. this part works because when i hover over the list i get something like "javascript : open(Something) " in the status bar.
to test this i create this function:
However when i click on the links i get an error:
I think what it is trying to do is find out what is assaigned to 'Something' (or how 'Something is defined)but 'Something' is the definition. 'Something is the definition of element at that part of the for loop.
I figured that a way to solve this is to tell the machine that whatever is assigned to element should be considered a string. But I don't know how to deal with the syntax of 3 quotes in each other because I would essentially need something like this:
Notice the 3 "s which ones will be "s and which ones will be 's and what about the 3rd one? Is it a " or a '. I've tried all sorts of combos but I can't figure out the right syntax.
Is there another way around this error? Sorry for the length of this... any help appriciated.
basically I get information from an external xml document like this
Code:
function run(file) {
t = file.getElementsByTagName("category");
for(i=0; i<t.length; i++) {
element = file.getElementsByTagName("category")[i].childNodes[0].nodeValue;
theMenu += "<a href='javascript:open(f, "+
element+")'>"+
element+
"</a><br>";
}
}
to test this i create this function:
Code:
function open(msg) {
alert(msg);
}
Code:
Error: 'Something' is undefined
I figured that a way to solve this is to tell the machine that whatever is assigned to element should be considered a string. But I don't know how to deal with the syntax of 3 quotes in each other because I would essentially need something like this:
Code:
theMenu += "<a href="javascript:open(f, ""+ element+"")">"+ element+ "</a><br>";
Is there another way around this error? Sorry for the length of this... any help appriciated.
Comment