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

152
Visualizações
I would like to turn this block of code into a keydown function that i could call from a html form
  SetPoint :<input id="input" type="text" name="setPoint" onkeydown="return keyispressed(event);"    max="5" min="1" /><br /> 



 SetPoint :<input id="input" type="text" name="setPoint" onkeydown="return keyispressed(event);"    max="5" min="1" /><br /> 
    
    
    input.addEventListener("keydown", function(e){
        var charValue= String.fromCharCode(e.keyCode);
        if(((!/^(\d+)?([.]?\d{0,1})?$/.test(this.value + e.key)) && (e.which != 8 )))
        {
            e.preventDefault()
      }
    })

I want the setpoint html input form to call a keydown fucntion and then run the following code thanks for any help provided

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

0

Few things:

  • Your HTML is invalid, You have duplicate ids which should be unique.

  • You should be selecting all inputs, looping through the list, and adding the event listener to each one

document.querySelectorAll('input').forEach(input => {
  input.addEventListener("keydown", function(e) {
    var charValue = String.fromCharCode(e.keyCode);
    if (((!/^(\d+)?([.]?\d{0,1})?$/.test(this.value + e.key)) && (e.which != 8))) {
      e.preventDefault()
    }
  })
})
SetPoint :<input type="text" name="setPoint" max="5" min="1" /><br /> SetPoint :<input type="text" name="setPoint" max="5" min="1" /><br />

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