These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

multiple list box duplicate value checking

lpp
Registered: Sep 18 2008
Posts: 6
Answered

I have a form with multiple list boxes, each containing the same values. However, a value can only be chosen once. Here's the code I'm using to check the exit event of the first listbox:

var juris = new Array(3);
for (x = 0; x < 2; x++){
juris[x] = xfa.resolveNode("jlist["+x+"]").rawValue;
}
for (y in juris){
if (y != 0){
if (this.rawValue == juris[y]){
xfa.host.messageBox(this.formattedValue + " already listed","Information",3,0);
}
}
}

This works well but I have to change the code for each listbox so it doesn't check itself. I do this using the if (y != 0) for list[0] and would change this to if (y != 1) for list[1], etc.

Can anyone tell me how to capture the current lists' index value ([0],[1].etc) within the array so I can assign that value to variable z and use if (y != z) for each list?

Thanks

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Each element in the XFA has an "index" property. Use this for the comparison. Capture the form fields instead of the values. You can also simply this down to a single loop;

I tested this code in the change event for the drop-down. It also blocks the selection by restoring the previous value
var FldList = this.parent.resolveNodes("jlist[*]");for(var i=0;i<FldList.length;i++){if( (i != this.index) && (xfa.event.change == FldList.item(i).rawValue) ){xfa.host.messageBox(this.formattedValue + " already listed","Information",3,0);xfa.event.change = xfa.event.prevText;break;}}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

lpp
Registered: Sep 18 2008
Posts: 6
thanks for the answer and coding pointers.
much appreciated!