JSFiddle - React, Tailwind, and code Playground

by littlesandra88

HTML

<select>
    <script type='text/javascript'>
        insert_dropdown("val2", $("#select1"));
    </script>
</select>

<select>
    <script type='text/javascript'>
        insert_dropdown("val3", $("#select1"));
    </script>
</select>

JavaScript

var container = {
    val1: 'AAA',
    val2: 'BBB',
    val3: 'CCC'
};


//Assuming options is an array of code/value pair
insert_dropdown(options,
default, $("#select1"));

function insert_dropdown(options,
default, container) {
    $.each(options, function() {
        container.append("<option value='" + this.code + "'>" + this.value + "</option>");
    });
    container.val(
default); //This will select the default option
}