lundi 25 juillet 2016

How to add value from multiple select option with Javascript array

how i get value for all select option with multiple select with array Java script.

code like this:

<select name="color[]" id="colorlist1"></select>
<select name="color[]" id="colorlist2"></select>
<select name="color[]" id="colorlist3"></select>
<select name="color[]" id="colorlistXY"></select>


var color = ["red","green","blue","brown"];
var sel = document.getElementById('colorlist1');
    var fragment = document.createDocumentFragment();
    color.forEach(function(color, index) {
        // body...
        var opt = document.createElement('option');
        opt.innerHTML = color;
        opt.value = color;
        fragment.appendChild(opt);
    });
    sel.appendChild(fragment);

https://jsfiddle.net/zoet0648/1/

Thanks.

what i want to make is like this form and value of select option from array database

Aucun commentaire:

Enregistrer un commentaire