Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

Getting a List's New Selection

Have you ever struggled to figure-out what item from a list (list box or drop down list) a user had just selected in the list’s Change event? If so, it’s possible you were trying to use the


property in order to get at this information.

Unlike other objects such as exclusion groups, the rawValue property of a list object doesn’t reflect the new selection until the selected value is committed to it (by the user tabbing or clicking away from the list). That means that if you’re trying to, say, make a certain field visible at the moment when a particular item in the list is selected, you can’t use the rawValue property because it still contains the old (previous selection) value.

Instead, you must use the


object/property of the Change event itself and possibly the list object’s


function in order to determine the value associated with the new selection.

When scripting any XFA event, you always have access to properties (information) of that event via the


object. In the case of the Change event (which occurs when the list’s selection changes), the


property is of particular interest because it contains the text portion of the item that was just selected in the list. It’s important to note that this is only the text portion because if your list contains items with values that differ from their text (you’ve associated both a text and value part to each item in the list), you’re probably even more interested in determine the value associated with the new text that was just selected in the list. Fortunately, that’s an easy problem to solve as well:

this.boundItem( xfa.event.newText ); // JavaScript
$.boundItem( xfa.event.newText ) // FormCalc

will return the value bound (associated) to the text from the list’s new selection.

So there you have it: When handling a list object’s (list boxes or drop down lists) Change event, don’t rely on the rawValue to get the new selection: Use xfa.event.newText and boundItem(text) instead.

Posted by Stefan Cameron on September 23rd, 2006
Filed under Events,Scripting
Both comments and pings are currently closed.

3 Responses to “Getting a List's New Selection”

  1. Alessio on October 6th, 2006

    It seems to me that this doesn’t work with multichoice listbox, isn’t it?


  2. Alessio on October 7th, 2006

    OK, I solve the problem…
    I put this script in the click event of a button and this button is executed when we exit from the listbox.
    Remember that you have to put a default value for the listbox or the script won’t work.

    if ( xfa.form.form1.ListBox1.rawValue != null)
      var lbValue = xfa.form.form1.ListBox1.rawValue.split("\n");
      var nodeList = xfa.form.form1.ListBox1.resolveNode("#items").nodes;
      var lbText = "";
      for (var j = 0; j Alessio
  3. Stefan Cameron on October 7th, 2006

    Alessio — Thanks for that script!