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

171
Visualizações
How to disbale line breaks in textarea on focus

So I have a textbox(input) and I have added a functionality to it that if the user presses enter, the focus shifts to a textarea element. But for some reason, a line break gets added after focus on the textarea and the cursor appears. I tried using (keydown.enter)="$event.preventDefault()" on the textarea but it only prevents line breaks when the cursor is in the textarea. How do I ensure line breaks are not added into the textarea on focus?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Hope I understand your requirements exactly.

Two things we need to achieve for your requirement.

1, disabled press enter in textarea

$('textarea').keypress(function(e){
    if ( e.which == 13 ) e.preventDefault();
});

2, fire press shift key, we implement by focus next element

$("#next_element").focus();

final code like below

$('textarea').keypress(function(e){
    if ( e.which == 13 ){
        $("#next_element").focus();
        e.preventDefault();
    }
});
<html>
    <head>
        <title>Textarea</title>
    </head>
    <body>
        <form action="javascript:void(0);" method="post">
            <textarea name="description" placeholder="Description" required></textarea>
            <input type="text" id="next_element" placeholder="Next element" required />
            <input type="submit" />
        </form>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>        
    </body>
</html>

about 4 years ago · Santiago Trujillo 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