You are viewing limited content. For full access, please sign in.



Forms 11 New Form Designer - Javascript to set a Field Value to the Text value in a Dropdown choice

asked on March 14 Show version history

I am working in the new Forms 11 Form designer trying to employ the LFForm object syntax for something I used to be able to with older code in the Classic Form Designer, and I am stumped!  I am trying to set a single line field to the text of a choice (a city name) in a dropdown menu (not the associated assigned value, which is a permit number).

The following code works to set the value of Field 22 to the assigned value of Field 2 [the permit number], but not the TEXT of the choice [the city name] of Field 2. I want to set it to the city name.

LFForm.onFieldChange(function(){ LFForm.setFieldValues({fieldId: 22}, LFForm.getFieldValues({fieldId: 2})) }, {fieldId: 2})

This is the code that I would have used in the Classic designer interface to accomplish this:

$(document).ready(function () {  
  $('#q2').on("change", function(){ 
   var citytext = $('#q2 option:selected').text();
   $('#q22 input').val(citytext).change(); 


Can anyone help me revise my code to specify the Field2 choice text, rather than its assigned value?  Thank you!

0 0


replied on March 15

Thank you so much, Zhiyong. I did implement a workaround by assigning values to the choices that included all the info and just used two other fields parse out the different string components I needed separately (using calculations). That would have been more challenging if the permit values were not set at a fixed character length like in this case, though.

Retrieving the label text of the dropdown would have been much easier (and we run into this need periodically), so I hope to see that supported in future updates. Thanks again!

2 0
replied on March 15

Hi Bethany,


There is similar question before, . However, retrieving the label text of dropdown field in the new form designer is not supported so far, we will evaluate this and make it into a feature request afterwards.

As a workaround, you can select the "Assign values to choices" option in Dropdown field configuration, then the Label and Value are sharing same text. Let me know if this is doable for you.

1 0
replied on April 7

Hi Bethany,

From dev's feedback, labels of drop-down field can be retrieved by findFields APIs. I managed to achieve described usage with following code.

LFForm.onFieldChange( //2 is id of drop-down field; 3 is id of single line field;
    var field = LFForm.findFieldsByFieldId(2)[0];
    LFForm.setFieldValues({fieldId: 3}, field.options.find((x) => x.value === 
  }, {fieldId: 2})


0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.