0

I try to detect text changing in live on an input text. Here is my attempt to do this :

This code is for JQuery includes version.

<script src="http://code.jquery.com/jquery-1.9.0.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.0.0.js"></script>

This code is for the form. Like you will see, a simple form with 2 input text (id and password) and a button.

<form method='post'>
    <input type="text" name="id" id="id" placeholder="mail adress" />
    <input type="text" name="pass" id="pass" placeholder="password" />
    <input type="submit" name="login" id="login" value="login" />            
</form>

And finally the JQuery code that seems not working. I placed it in the <body></body> which also contains my form.

<script type='text/javascript'>
    $('#id').on('input', function () {
        alert('text changed');
    });
</script>

This short code doesn't seems to work. I followed a precedent question asked in this site, but this solution didn't help me.

The most strange thing is that it works when I copy paste this code in a snippet, but doesn't with a simple html file located in my PC. So I think the problem come from my jquery includes, possibly..

May someone light my lantern ?

Community
  • 1
  • 1
Anwar
  • 4,162
  • 4
  • 41
  • 62
  • 1
    may be, you need to put in inside a [dom ready handler](http://learn.jquery.com/using-jquery-core/document-ready/) – Arun P Johny Oct 02 '14 at 16:32
  • This is exactly the solution. Thank you so much @Arun P Johny ! I'm putting the solution refering to you asap – Anwar Oct 02 '14 at 16:34

1 Answers1

0

Thanks to Arun P Johny, the solution was to put my handler directly into the ready. Solution is the following so :

<script type='text/javascript'>
    $(document).ready(function() {
        $('#id').on('input', function () {
            alert('text changed');
        });
    });         
</script>
Anwar
  • 4,162
  • 4
  • 41
  • 62