Jump to content

Problems inserting JS line in XSLT


Leither

Recommended Posts

I've been working with an XSLT document and have been trying to simiply insert some dom/JavaScript functions. When I try to put this line in(The first line just sets it up, and I'm positive it's not the one causing the problem):

var seturl=document.getElementById(type).selectedIndex;document.write("<iframe src=\"document.getElementsByTagName('option')[seturl].value\" />");

It gives me this error: A string literal was expected, but no opening quote character was found. Removing the slashes in front of the quotes for the source attribute processes my file, but gives a JavaScript error, I've narrowed it down to the specific line above. If I try to replace the quotes with single quotes it gives me this error: Required white space was missing.Taking out the quotes all together gave me the same error as the first one. I've tried using the entities mentioned in a previous thread, but it just outputted the code(& #34 and I did put the semicolon on the end, just don't want the forum to display quotes. And did it without the semicolon, just in case. :)) and gave me the first error again.So, in short, I just want to know why my JS won't work. Any help is welcome, thanks. :) (I sound like a stiff person in this, I know, I just don't know how else to put it). Thank you for any help, and I hope that the XSLT forum is okay instead of JavaScript.P.S.: I've found that only the opening quote seems to trigger this reaction, leaving the second at the end of the src attribute with the slash in front of it gives me no error, just the first.

Link to comment
Share on other sites

Try to surround all of your JS code with CDATA and see if it does any good.I think that without it, your JS targets the XSLT file, rather then the output HTML file. Placing CDATA should escape the JS in a fashion that should enable it only in the output, but I'm not sure about that.

Link to comment
Share on other sites

Hah. Honestly, I didn't believed it would, and believe me, it's been asked A LOT.Now this is one of the cases for which I still stick to forums, and this one in particular - where helping others makes you learn something for youself as well :) .

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...