Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

select add option js

//add one option
let select = document.getElementById('mySelect');
let option = document.createElement('option');

option.value = 1;
option.text = 'option 1';   
select.add(option);


//Add few option , exemple from Json 'items'
for (const key in items) {
  if (Object.hasOwnProperty.call(items, key)) {
    const item = items[key];

    let option 		= document.createElement('option'); // again init option

    option.value 		= item.id;
    option.text 		= item.name;

    select.add(option);
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #select #add #option #js
ADD COMMENT
Topic
Name
8+7 =