Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
Making options from 0 to 100 with javascript

I need to make section with options in it going from 0 to 100 when the page is open, in html is simple just type it all out :D, but i think i can do this in java script but i am not quite sure how. Here is my html and a little bit of js code:

function options() {
            var section = document.getElementById("section");
                for(var i = 0;i < 100;i++){
                    section.innerHTML = "<option value="i">"+i+"</option>";
            }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <section id="section" onload="options">
        
    </section>

    

</body>
</html>

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Here's How you can do it -

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <select id="mySelect" onload="options()"></select>
</html>

<script type="text/javascript">
    var selectElem = document.getElementById("mySelect");
    for (var i = 0; i < 100; i++){
      var element = document.createElement("option");
      element.innerText = i + 1;
      selectElem.append(element);
    }
</script>

Here's the working example

about 4 years ago · Juan Pablo Isaza Denunciar

0

<section> tag doesn't support onload.

You can check w3schools onload event and MDN: onload, the tags support onload are: <body>, <frame>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>

So you can move onload="options()" to <body> then escape the double quotes and use <select> instead of <section> as the comments mentioned.

function options() {
            var section = document.getElementById("section");
                for(var i = 0;i < 100;i++){
                    section.innerHTML += "<option value=\"i\">"+i+"</option>";
            }
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body onload="options()">

    <select id="section">
        
    </select>

    

</body>
</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda