jackhao
jackhao

Reputation: 3817

Jquery trigger when input changes not works

I am trying to use Jquery to trigger the event when user change the value in my input.

It is supposed to be fairly easy, however, I tried all the ways but none of them works for me.

Here is my HTML:

<input id="size" type="text" name="Size[mm]" style="width:40px; margin-top:5px; padding-left:10px;" value="1.00" maxlength="6" size="10">

Here are my jQuery:

I tried:

<script>
$('#size').bind('keyup mouseup change',function(){
       alert('Yeah!');
});
</script>

And

<script>
$("input#size").change(function(){
          alert('Yeah!');
}).change();
  </script>

And

<script>
$("#size").change(function(){
          alert('Yeah!');
});
</script>

However, none of these works and nothin happens in my Firebug..

Any ideas?

Thanks

Upvotes: 0

Views: 298

Answers (1)

epascarello
epascarello

Reputation: 207501

If they are not working, you are probably adding the event handlers before the element is rendered. Use document ready.

<script>
    $( function(){
        $('#size').bind('keyup mouseup change',function(){
            alert('Yeah!');
        });
    });
</script>

Upvotes: 4

Related Questions