0
votes

Before describing the problem, I would like to add that I have looked for this problem on google and have found many solutions but none related to XPAGES. Since, Xpage have a unique method to generate the field id I am facing this problem. I have also posted the same question here on IBM forum and awaiting the reply there(http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=EDEBB14BDF2E804F85257BE8001E4F76):

Problem:

I am trying to pass dynamic id to the default function getElementById with no success. To explain it clearly, I have a front end validation for specific fields. This fields are stored n database. So, I have a for loop running for all the fields. The problem here is that XPages generates the Id dynamically and hence for the same form if there is a hierarchical tabbed panel then the Id also included the tabbed panel Id in it.

Here is the code view of the problem:

The standard method to retrieve the value(CSJS) is:

document.getElementById("#{id:inputText1}").value;

However, if I try to pass in a dynamic id. It doesn't work. I have tried "n" number of approaches I found on Google but none regarding this problem. One solution I tried here was:

var x = "inputText1";

document.getElementById("#{id:"+x+"}").value;

Any help would really be appreciated. Really eager to hear some good suggestion.

1

1 Answers

1
votes

The "#{id:inputText1}" part is computed at the server before the page is served so it's too late to set the ID in client side JS.

To set the ID in SSJS you can do this:

document.getElementById("#{javascript:var x='inputText1'; getClientId(x)}").value;

With getClientId you can also build a CSJS array of IDs in in SSJS. Then you can loop that array in CSJS. You would build the array this way:

var strIDs = ${javascript:'["a","b","c"]'};