0

The following works:

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'blah');");

The following:

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'document.forms[0].elements['MYHiddenValue'].value');");

or

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'document.forms[0].elements['MYSecondHiddenValue'].value');");`

Gives:

[INFO:CONSOLE(1)] "Uncaught SyntaxError: missing ) after argument list", source:  (1)

What am I doing wrong?

2
  • You've got weird characters in that code, and in particular there are some single-quotes that aren't single-quote characters (around the "MYHiddenValue" strings). Commented Feb 13, 2017 at 17:07
  • @Pointy:That was a copy/paste issue. Fixed OP Commented Feb 13, 2017 at 20:17

3 Answers 3

2

Replace all ’ characters with '

(Copy / paste from here as they look like each other)

Edit after the comment from OP below.

First failing command :

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'document.forms[0].elements['MYHiddenValue'].value');");

This has a pair of single quotes which will cause a syntax error when the line executed and produced the string. It should produce an escaped pair of single quotes so the line should contain an 'escaped' backslash:

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'document.forms[0].elements[\\'MYHiddenValue\\'].value');");

Second option would be using double quotes and escaping each with a single backslash at the first stage like :

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements['MYHiddenValue'].value+'</html>', 'document.forms[0].elements[\"MYHiddenValue\"].value');");

Second command has also a similar error on 'MYSecondHiddenValue'.

The reason that first command is not failing is that it is building the html string by adding three separate strings which is not causing a quote issue.

But this also makes the three commands differ each other. First command adds the value of document.forms[0].elements['MYHiddenValue'] and the other two adds the string "document.forms[0].elements...value". So we don't know which one is correct without knowing what showHTML() does exactly.

Sign up to request clarification or add additional context in comments.

2 Comments

That was a copy/paste issue. Fixed OP
Edited the answer.
1

I believe this is the problem. In your first (working) example,

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements[’MYHiddenValue’].value+'</html>', 'blah');");

the second embedded parameter 'blah' does not have any internal quotes. However, in your first non-working example,

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements[’MYHiddenValue’].value+'</html>', 'document.forms[0].elements[’MYHiddenValue’].value');");

there is an embedded quote in a section of the parameter that should be evaluated. The following sub-string (found in both examples has a string ('') concatenated with code that evaluates to a string concatenated with another string, the closing HTML tag.

'<html>'+document.forms[0].elements[’MYHiddenValue’].value+'</html>'

In the non-working second example,

 'document.forms[0].elements[’MYHiddenValue’].value'

You have a string that I believe just needs to be evaluated. JavaScript is seeing this as a string like as below, but this is not what you want.

 'document.forms[0].elements[’

I believe if you remove the outer pair of single-quote marks in this non-working example, it will work, as the code will evaluate. If you need it to just be a string, then you need to escape the inner single-quote marks as in

 'document.forms[0].elements[\'MYHiddenValue\'].value'

Comments

0

Well, looking at your code right now, I can see that

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements[’MYHiddenValue’].value+'</html>', 'document.forms[0].elements[’MYHiddenValue’].value');");

Is really one big string, (or two that are concatinated), try changing it to:

loadUrl("javascript:HtmlViewer.showHTML" + "('<html>'+document.forms[0].elements[’MYHiddenValue’].value+'</html>'", "'document.forms[0].elements[’MYHiddenValue’].value');");

perhaps?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.