• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Creating an array, help required please...

Participant ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

Hi there,

I've written some code to create a combo box and all works fine in JS debugger.

The values for the combo box are passed in via an array like this:

var aOptions = new Array('Choose an Item','Apple','Pear','Banana','Grape','Orange');

I'm now trying to pick up the values from a text field, on a form, and generate the combo box.

I've tried a number of different ways to take the values from the text field and generate separate combo items. The value taken from the text field ends up as one big item.

I've tried splitting down the values from the text field in a number of ways, for example using a comma to separate them, but as yet haven't succeeded in generating separate combo box items.

 

As mentioned earlier, the code above works fine in the debugger it's when I try to pick up the values from a text field I'm having issues.

Please can someone point me in the right direction.

 

Thanks in advance.

TOPICS
Mac

Views

115

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2022 Jul 27, 2022

Copy link to clipboard

Copied

Post your code, please.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

Hi Gilad,

Thanks for your response.

 

I'm picking up the parameters from 2 form elements, already on the page, as shown below and then passing them to the combobox creation. The JS that picks up the form values, and passes them to the code that generates the combo box, is the action in a Submit button.

The code works fine apart from the combo box values being picked up as one chunk rather than individual values from the text field.

var listBoxName = this.getField("fieldName").value;
var listVals = this.getField("listBoxVals").value;

var inch = 72; // points per inch
var page = this.pageNum; // zero based page for field
theFieldName = listBoxName;
var aOptions = new Array(listVals.split('\r'));


// GENERATE COMBO BOX...

 If I use the code below in the debugger it works fine: 

theFieldName = 'comboBoxName123';
var aOptions = new Array('Choose an Item','Apple','Pear','Banana','Grape','Orange');

I'm thinking it has something to do with passing the parameters via form fields rather than from the debugger?

Thanks again for the help 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2022 Jul 28, 2022

Copy link to clipboard

Copied

This code is very partial. Please post the full code, and maybe the file itself, for help with it.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

Hi Gilad,

Thanks for the reply.

 

Having done some testing I've solved it.

When executing the code in the debugger I need to pass the combo box options as an array. 

var aOptions = new Array('Choose an Item','Apple','Pear','Banana','Grape','Orange');

However, when passing the options via a form element, a text field, the options can be passed as a comma separated list: Choose an Item,Apple,Pear,Banana,Grape,Orange

This is then broken down using var aOptions = listVals.split(','); and aOptions passed to the combo box creation:

var f = this.addField({cName: theFieldName, cFieldType: "combobox", nPageNum: page, oCoords: aRect})
f.setItems(aOptions); // set options for selection

When using debugger the options are passed as array but when taking the options from a form element, a text field, it doesn't look like an array or am I mistaken?

 

Thanks again for the input.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

No, you're correct. When you get the value of a text field it's a string, not an array. You can use the split command to convert it to one.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 29, 2022 Jul 29, 2022

Copy link to clipboard

Copied

LATEST

Ah! Thanks for the explanation Gilad.

That explains why I don't need the new Array bit.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines