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

288
Views
Add a special character on keypress not working

I would like to add an accented character – á – whenever we use a key combination of Alt + 'a'. Then the same for é with the combination of Alt + 'e'.

I tried to achieve it with this function, however, the results are far from perfect:

$('input').bind('keypress keydown keyup', function(event) {
    if (event.altKey && event.key == 'a') {
        event.preventDefault();
        this.value += 'á';
    }
});

When I use this key combination, I don't get the desired result, instead, I get the Polish "ą".

However, when I only use event.key == 'a' without the event.aktKey, it works and adds value to the input.

Could you please explain why this happens and provide a solution? Thank you.

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

0

There is no reason within your code or jquery that you would get "ą".

But anyway, why bind to all three events: keypress, keydown and keyup? That will result in multiple characters being added for a single key press.

The following seems to work fine.

$('input').on('keydown', function (event) {
    if (event.altKey && event.key == 'a') {
        event.preventDefault();
        this.value += 'á';
    }
});

console.log('\xE1' === 'á');    // true
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input></input>

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!