Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
disable enter key on specific textboxes

I was looking for a way to do this, got a few scripts, but none of them is working for me.

When I hit enter in my textboxes, it shouldn't do anything.

I have tried a few JavaScript and jQuery scripts, but nothing is working for me.

$(document).ready(function() {
    $('#comment').keypress(function(event) {
        if (event.keyCode == 13) {
            event.preventDefault();
        }
    });

    $('#comment').keyup(function() {
        var txt = $('#comment').val();
        $('#comment').val(txt.replace(/[\n\r]+/g, " "));
    });
});
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

This works for me.

$('textarea').keypress(function(event) {
    if (event.keyCode == 13) {
        event.preventDefault();
    }
});

jsFiddle.

Your second piece looks like it is designed to capture people pasting in multiple lines. In that case, you should bind it to keyup paste.

over 4 years ago · Santiago Trujillo Denunciar

0

If you want to prevent Enter key for specific textbox then use inline js.

<input type="text" onkeydown="return (event.keyCode!=13);"/>
over 4 years ago · Santiago Trujillo Denunciar

0

It stops user to press Enter in Textbox & here I return false which prevent form to submit.

$(document).ready(function()
    {
        // Stop user to press enter in textbox
        $("input:text").keypress(function(event) {
            if (event.keyCode == 13) {
                event.preventDefault();
                return false;
            }
        });
});
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda