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

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

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