[JavaScript] Cargar valores de una función de JS a un select en HTML

HTML:

<form id='miFormulario'>
<select name="provincia" id="provincia">
    <option value="">Seleccione una Provincia...
</select>
</form>

JavaScript:

miformulario = document.querySelector('#miFormulario');
window.addEventListener("load", function() {
        cargarProvincias(event);
    }, false);

//Funcion para cargar las provincias al campo "select".
function cargarProvincias() {
    //Inicializamos el array.
    var array = ;
    //Ordena el array alfabeticamente.
    array.sort();
    //Pasamos a la funcion addOptions(el ID del select, las provincias cargadas en el array).
    addOptions("provincia", array);
}

//Funcion para agregar opciones a un <select>.
function addOptions(domElement, array) {
    var selector = document.getElementsByName(domElement);
    //Recorremos el array.
    for (provincia in array) {
        var opcion = document.createElement("option");
        opcion.text = array;
        selector.add(opcion);
    }
}
PandaGG
Lok'tar ogar

Dejar respuesta

Please enter your comment!
Please enter your name here

Sponsor

Últimos

Clubhouse Casino Handbook to Evaluating an Virtual Gambling Platform

Evaluating a dependable virtual casino platform calls for more than merely examining the sign-up promotion or the quantity of available games. Search queries including...

favorite article 528648

favorite article 528648

Casino online Luckia Bilbao: guía de seguridad

1. Registro y verificación en Luckia Bilbao2. Bonos de bienvenida y requisitos de apuesta3. Métodos de pago y velocidad de retiro4. Experiencia móvil y...

Casino Batelière mobile : guide complet pour les joueurs français

Pourquoi choisir le Casino Batelière mobile ?Inscription rapide – étapes détailléesCréer son compte en moins de 5 minutesVérification d’identité (KYC) : pourquoi et commentLes...

1xbwt APK Bonus Guide: Welcome Offer, Wagering Requirements & US Payment Options

1xbwt APK – Practical Guidance for US Players What Is the 1xbwt APK and Who Is It...