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

327
Views
¿Cómo generar un número descendente en el cuadro de texto html?

Código HTML

 <form id = "numbersdescendingodd"> Resultdescendingodd : <input type = "text" name = "resultdescendingodd" id = "dodd" max = "20"><br> <input type = "button" onclick = "descendingodd()" value = "Clickhere"> <br> </form>

código JavaScript

 function descendingodd(){ var x = 0 for(var i = 21 ; i>=1; i-=2){ var result = document.getElementById('dodd'); result.value = (`${i}`) } }

quiero que mi cuadro de texto de salida sea: 21,19,17,15, etc.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Está configurando el valor del cuadro de texto para cada número impar descendente uno a la vez y, por lo tanto, una vez que su código termine de ejecutarse, se dejará configurado en el último número (1).

Intente cambiar result.value = ( ${i} ) a result.value += i + ',' . No hará exactamente lo que quieres (tendrá una coma después del último número), pero supongo que podrás resolverlo a partir de ahí.

about 4 years ago · Juan Pablo Isaza Report

0

Reemplace su función descendingodd con esto

 function descendingodd(){ var x = ""; var result = document.getElementById('dodd'); for(var i = 21 ; i>=1; i-=2){ x += i; x += ","; } result.value = x;}
about 4 years ago · Juan Pablo Isaza Report

0

 function descendingodd() { const text = document.getElementById('dodd').value; const numbers = text.split(',').map(Number); const r = numbers.sort(function(a, b){return ba}); document.getElementById('dodd').value = r.join(); }
 <form id = "numbersdescendingodd">Resultdescendingodd : <input type = "text" name = "resultdescendingodd" id = "dodd" max = "20" value="5,17,21,19"><br> <input type = "button" onclick = "descendingodd()" value = "Clickhere"> <br> </form>

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!