frosty
frosty

Reputation: 5370

how to get change event on created fields in jquery

I have some jquery code the creates an quantity text box. Like so

<input type="text" value="1000" class="qty" name="[0].Quantity">

I wish to add some validation to this text box but can hit the method. I believe i need to utlise Live(). But can't quite figure out how this is implemented.

This is where i'm at

  $(document).ready(function () {
        $(".qty").change(checkValue);
    });

    function checkValue() {

        alert("on change");
    }

Upvotes: 1

Views: 47

Answers (1)

Nick Craver
Nick Craver

Reputation: 630549

The .live() syntax would look like this:

$(function () {
    $(".qty").live('change', checkValue);
});

You can test it a bit here, keep in mind this fires on blur usually though, you may want the keyup, keydown or keypress events rather than change if you're looking to do it per character.

Upvotes: 1

Related Questions