Jump to content

javasript XML problem


Guest carl lucas
 Share

Recommended Posts

Guest carl lucas

I'm having issues trying to pass a variablebasically I get information from an external xml document like this

function run(file) {	t = file.getElementsByTagName("category");	for(i=0; i<t.length; i++) {	  element = file.getElementsByTagName("category").childNodes[0].nodeValue;	  theMenu +=	"<a href='java script:open("+			element+")'>"+			element+			"</a><br>";	}}

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 "java script: open(Something)" in the status bar.to test this i create this function:

function open(msg) {   alert(msg);}

However when i click on the links i get an error:

Error: 'Something' is undefined

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:

	  theMenu +=	"<a href="java script:open(""+			element+"")">"+			element+			"</a><br>";

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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...