Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

336
Visualizações
how to output descending number in html textbox?

HTML code

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

Javascript code

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

i want my output textbox are : 21,19,17,15,etc

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You are setting the textbox's value to each descending odd number one at a time and so once your code finishes running it will be left set to the last number (1).

Try changing result.value = (${i}) to result.value += i + ','. It won't do exactly what you want (it'll have a comma after the last number) but I'm guessing you'll be able to figure it out from there.

about 4 years ago · Juan Pablo Isaza Relatório

0

Replace your descendingodd function with this

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 Relatório

0

function descendingodd() {
  const text = document.getElementById('dodd').value;
  const numbers = text.split(',').map(Number);
  const r = numbers.sort(function(a, b){return b-a});  
  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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda