Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Can i use a variable, while referring a text field?

Avatar

Level 8

Hello

I have to set the readOnly property to some fileds DYNAMICALLY (i mean, until run time, i dont know Which fields are readOnly and which are not?  .

So, i want to replace the TextField1 dynamically with all the fileds in the below syntax. So, can i put some variable in the position of TextField1? if so, How can i do that?

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField1").access = "readOnly";

xfa.resolveNode("VISITOR.Page3.SubFrom1.MyVariableComesHere").access = "readOnly";

How can i put the variable in the red position?

In details:

Say, i have 5 fields, then, i want to make them readOnly, then i hv to write as below,

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField1").access = "readOnly";

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField2").access = "readOnly";

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField3").access = "readOnly";

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField4").access = "readOnly";

xfa.resolveNode("VISITOR.Page3.SubFrom1.TextField5").access = "readOnly";

Actually, my requirement is differnent (I know at run time only...that Wht wht fields i hv to set readOnly and wht wht fields should okay for input enable), for that reason i want to use a VARIABLE in the 'position' of TextField1, TextField2.....like bleow

var myVariable

myVariable = TextField1

LOOPing the ARRAY

xfa.resolveNode("VISITOR.Page3.SubFrom1.myVariable").access = "readOnly";

PLs. let me know Can i sue a variable like that? if so, what is the correct syntax (pls.  suggest me a SYNTAX error free code, bcz am very very beginner to this)

THank you

THank you

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can use the following way..

var myVariable

myVariable = TextField1

xfa.resolveNode("VISITOR.Page3.SubFrom1." + myVariable + "").access = "readOnly";

Thanks

Srini

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

You can use the following way..

var myVariable

myVariable = TextField1

xfa.resolveNode("VISITOR.Page3.SubFrom1." + myVariable + "").access = "readOnly";

Thanks

Srini