N
N
Nikolay Baranenko2017-05-15 17:24:25
JavaScript
Nikolay Baranenko, 2017-05-15 17:24:25

How to create an optgroup with a label on the select?

Hello.

On the form I create a form element of type select

var select = document.createElement("select");
        select.name="main_select_region";
        //select.className="selectpicker show-tick form-control";
        select.setAttribute('class', 'selectpicker');
        select.setAttribute('data-live-search', 'true');
        select.setAttribute('data-size', '15');

I dynamically add to it in a cycle from JSON
for (var i = 0; i < jsondata.regions.length; i++) {
select.options[i]=new Option(jsondata.regions[i].name, jsondata.regions[i].name);
...


How to add to it ? <optgroup label="Группа1">

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question