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

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

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