I have an incoming message hitting my XSL page. On this XSL page I have javascript to catch it and place the items in the appropriate places.

There is the possibility that these messages can have double quotes and other escape characters.

I am using

parent.myForm.hiddenValue.value = encodeURIComponent(<xsl:value-of select="INCOMING/MESSAGE/BLAH">)

This works if the message has special characters but seems to give me a JS error if it does not.
If the value coming in, nature. It will give me the error, nature is undefined.

Any ideas on how to use encode for both scenarios?

Thanks!