Dropdown multiple selection to populate text field

Hi! I am making a form for a Non-profit organization.

They want to select multiple items from a drop down field, I was thinking that while they are selecting the possibles selections from the drop down they can be copying simultaneously in to a text field.

Example:

Abilities Dropdown:
- Literacy
- Medical Services
- Mentoring
- Music
- Outdoor Recreation
- Tutoring
- Translation
- Recruiting

Text Field: (They choose only 4 selections from the drop down)
Literacy, Tutoring, Translation, Mentoring.


Christian Ortiz


2 Answers

Voted Best Answer

A dropdown can only have one selection at a time. A listbox can have multiple selections. Are you looking for a control that can select multiple items at the same time, or are you trying to simulate a multi-selection with a dropdown control where the user selects four items, one after the other, and these four items are then added to the text field?

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


By Karl Heinz Kremer   

This can be done, but is a bit complex. Let's assume you have one dropdown and a text field named "Text1", then do the following:

Create a document level script using the following script:

function UpdateTextField(doc, fieldName, newValue)
{
    var ar = [];
    // Get the values currently stored in the text field and 
    // convert them to an array
    var v = doc.getField(fieldName).value;
    if (v.length > 0) {
        var ar = v.split(",");
    }
    // Do we already have newValue in the array? 
    var foundIt = -1;
    for (var i=0; i<ar.length; i++) {
        if (ar[i] == newValue) {
            foundIt = i;
            break;
        }
    }
    if (foundIt != -1) {
        // remove the item
        ar.splice(i, 1);
    }
    else { // add the item at the end
        ar.push(newValue);
    }
    // If we have more than four elements, 
    // remove the oldest one
    while (ar.length > 4) {
        ar.shift();
    }
    // conver the array to a string
    this.getField(fieldName).value = ar.join();
}

In your dropdown control, go to the Options tab and make sure that "commit selected values immediately" is selected, then go to the "Validation" tab and select to use a custom validation script. Use this one line script:

UpdateTextField(this, "Text1", event.value);

As you can see, we are specifying the field name as the 2nd parameter to this function call.

This should do the trick. When you select a value that's already in the list, it will be removed, and if you select more than four values, the oldest value will be removed.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


Karl Heinz Kremer   


Please specify a reason: