Eval() do not work in Javascript

Avatar

Avatar

_SekharN_

Avatar

_SekharN_

_SekharN_

02-08-2006

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

Replies

Avatar

02-08-2006

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



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



Chris

Adobe Enterprise Developer Support

Avatar

Avatar

_SekharN_

Avatar

_SekharN_

_SekharN_

02-08-2006

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

02-08-2006

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

Avatar

_SekharN_

Avatar

_SekharN_

_SekharN_

02-08-2006

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

02-08-2006

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

Avatar

_SekharN_

Avatar

_SekharN_

_SekharN_

02-08-2006

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

02-08-2006

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