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

HTML5 Combobox adding more items?

Explorer ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

Hi,

I am looking for a way to add more dropdown items to the HTML5 combobox component by adding them to the items categoryScreenshot 2018-02-02 12.00.23.png

I am able to access the features of disabled, visible and value just fine by calling these lines

  • document.getElementById('COMBO_BOX_NAME').value :white_heavy_check_mark:
  • document.getElementById('COMBO_BOX_NAME').disabled :white_heavy_check_mark:
  • document.getElementById('COMBO_BOX_NAME').visible :white_heavy_check_mark:

But for some reason when I try to add objects to the item array nothing seems to happen?

Basic addition to arr object

var array = new Array();

var obj = new Object();

obj.label = 'Label';

obj.data = 'Data';

arr.push(obj)

Methods tried for adding to the combo box

  • document.getElementById('COMBO_BOX_NAME').items = array :cross_mark:
  • document.getElementById('COMBO_BOX_NAME').items.push(obj) :cross_mark:
  • document.getElementById('COMBO_BOX_NAME').items = [{label: 'Label', data: 'Data'}] :cross_mark: (Manual Entry seems to not work either!)

Is the items variable an array or an object? I've tried both and cant seem to store data there

Thanks

Views

907

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

correct answers 1 Correct answer

Explorer , Feb 01, 2018 Feb 01, 2018

Figured it out

To append new data you use the add() function. But before you do that you need to create an element

var obj = new Object();

obj.label = 'Label';

obj.data = 'Data';

var optionBox = document.createElement('option');

optionBox.label = obj.label;

optionBox.value = obj.data;

document.getElementById("COMBO_BOX_NAME").add(optionBox)

Votes

Translate

Translate
Explorer ,
Feb 01, 2018 Feb 01, 2018

Copy link to clipboard

Copied

Figured it out

To append new data you use the add() function. But before you do that you need to create an element

var obj = new Object();

obj.label = 'Label';

obj.data = 'Data';

var optionBox = document.createElement('option');

optionBox.label = obj.label;

optionBox.value = obj.data;

document.getElementById("COMBO_BOX_NAME").add(optionBox)

Votes

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
New Here ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

LATEST

This does´nt work.

Thanks.

Votes

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