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

154
Vistas
Why dont I get an alert when the text is added?

I know I can achieve this by adding the alert function in the button click listener body but I don't want to do it that way.I want whenever this textbox receives text, i get an alert.

this is the code

<!DOCTYPE html>
<html>
    <head>
 <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
        <title>Page Title</title>
    </head>
    <body>
        <form>
<input id="check" type="text" name="check" >

        </form>

        <button id="test">ClickMe</button>

    
    
  <script>  
  $(document).ready(function() {
    
    $('#test').click(function () {
        $('#check').val('Example') ;

    })

        $('#check').on('input propertychange paste change', function () {
        
          alert("text added");


        })

    })
    </script>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Setting the value with Javascript doesn't trigger an event, so you need to trigger the event manually. Also, you really only need the "input" event. The others are irrelevant or redundant.

$('#check').trigger('input');

Or you can chain it since you're using jQuery:

$('#check').val('N001-01-1356/2017').trigger('input');

Example:

$(document).ready(function() {

  $('#test').click(function() {
    $('#check').val('N001-01-1356/2017').trigger('input');
  })

  $('#check').on('input', function() {
    alert("text added");
  })
  
})
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>

<form>
  <input id="check" type="text" name="check">
</form>

<button id="test">ClickMe</button>

about 4 years ago · Juan Pablo Isaza 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