Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Haciendo opciones de 0 a 100 con javascript

Necesito hacer una sección con opciones que vayan de 0 a 100 cuando la página está abierta, en html es simple, simplemente escríbalo todo: D, pero creo que puedo hacer esto en java script, pero no estoy muy seguro de cómo. Aquí está mi html y un poco de código js:

 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 answers
Answer question

0

Así es como puedes hacerlo:

 <!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>

Aquí está el ejemplo de trabajo

about 4 years ago · Juan Pablo Isaza Report

0

La etiqueta <section> no admite onload .

Puede verificar el evento onload de w3schools y MDN: onload , las etiquetas compatibles con onload son: <body>, <frame>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>

Entonces puede mover onload="options()" a <body> luego escapar de las comillas dobles y usar <select> en lugar de <section> como se menciona en los comentarios.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!