Assigning Multiple Values to a Text Box by JS

  • Last update:July 10, 2025
  • Overview

    Problem

    You want to assign the value selected each time from a drop-down box to a text box and form a string with the values, as shown in the following figure.

    1.png

    Implementation Method

    You can add an After Editing event for the drop-down box widget, allowing you to concatenate the value selected each time from the drop-down box with the existing text box content. For details about the API description, see API for Getting and Setting Cell Values.

    Example

    Template Design

    Add a drop-down box widget and a text widget, as shown in the following figure.

    2.png

    Setting the Data Dictionary for the Drop-down Box Widget

    3.png

    Adding an After Editing Event to the Drop-down Box

    4.png

    The JavaScript code is as follows.

    var value = this.getValue();
    //Obtain the currently selected value.
    var text = _g().getCellValue(0, 1, 1);
    //Obtain the value of the cell where the text widget is located.
    if (value.length != 0) {
           //Exclude empty data.
           if (text.length == 0) {
                  _g().setCellValue(0, 1, 1, value);
                  //If the text box contains no value, assign the currently selected value directly to the cell where the text box is located.
           } else {
                  _g().setCellValue(0, 1, 1, text + "," + value);
                  //If the text box contains a value/values, append the current value to the existing one.
           }
    }

    Preview Effect

    Save the template and click Data Entry Preview. The following figure shows the effect.

    动图1.gif

    iconNote: 
    The effect cannot be previewed on mobile terminals.

    Template Download

    For details, you can download Assigning Multiple Values to a Text Box by JS.cpt.

    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy