Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Eval() do not work in Javascript

Avatar

Level 5
I need some help to make the following statement work in JavaScript event in LC Designer 7.1. The same statement works well if executed as FormCalc function. I need to replace "1" with some expression. I am having trouble executing "Eval" in JavaScript.



xfa.host.messageBox(eval(1+1))



Thanks in Advance.



SekharN
7 Replies

Avatar

Not applicable
Try xfa.host.messageBox("" + eval(1+1));



messageBox takes a string, your eval is returning a number.



Chris

Adobe Enterprise Developer Support

Avatar

Level 5
Thank you chris. I learned a new point. The statement works with the change you made. However it did not resolve my issue. Here is the part of code I have trouble with.



var sexp

var sname

sname = this.name

sexp = this.somExpression



sexp = sexp.replace(sname+"[0]", "TextDescription[0].access = \"open\"")

xfa.host.messageBox(sexp)

//xfa[0].form[0].form1[0].CustGroupA[0].TextDescription[0].access = "open"

eval(sexp)



The message gives me the right syntax(as commented), however TextDescription (TextField) is still non editable. The text field and the button are on the same detail line. And when user clicks Button (Edit button) the text field needs to be editable. Have any suggestions.



SekharN

Avatar

Not applicable
The problem is the '[' and ']' in the expression you are trying to eval(). Those are illegal characters in a JavaScript expression. As an alternative I would suggest using script like this on the button:



this.parent.TextDescription.access = "open";



Chris

Adobe Enterprise Developer Support

Avatar

Level 5
Chris, Finally I understood I am make round trip approach. Thank you for you line of code it works. However following line of code in FormClac works with no problem where as it do not work in Java script. And I feel like I am missing some thing with your statement "[" and "]". If I recall correctly the similar syntax works in HTML.



//FormCalc

eval(xfa[0].form[0].form1[0].CustGroupA[0].TextDescription[0].access = "open")



Thanks,

SekharN.

Avatar

Not applicable
Ok, bad choice of words, they aren't illegal, but they are defined in the JavaScript spec as punctuators. In this case you are trying to use them as a notational element to access a specific node in an XFA DOM, which is not how it's intended to be used. Since the JavaScript Interpreter has no idea of these things it doesn't like it.



It works in FormCalc because it is a scripting language designed by us specifically for working with an XFA DOM.



Chris

Adobe Enteprise Developer Support

Avatar

Level 5
Thank you Chris. You are very helpful. One more question on comparisons between FormCalc and JS.



I am looking for equivalents in JS for '$event.newText' of FormCalc. Any idea will help my situation.



Thanks,

SekharN.

Avatar

Not applicable
xfa.event.newText;



In general between the two languanges $ equates to xfa. Unless it is $. which equates to this in JavaScript.



I'm not 100% sure there aren't any exceptions to that, but I can't think of any at the moment and it's a good general rule.



Chris

Adobe Enterprise Developer Support

The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now