jQuery: The Write Less, Do More JavaScript Library

AJAX is not invoked for dynamically added input fields

View: New views
3 Messages — Rating Filter:   Alert me  

AJAX is not invoked for dynamically added input fields

by palgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Not a good title, but I'll explain little bit better here:

I got help here for another issue which was solved:

http://groups.google.com/group/jquery-en/browse_thread/thread/e9a2cfa80ec18c4c/33923a0f4ffc5729#33923a0f4ffc5729

So basically in one row there are 3 input fields, and writing to
numbers in the first two will set calculated value into the third
input field with ajax. This works fine with the two intial rows that
are displayed.

I added some javascript code to buttons to dynamically put in several
rows and remove them(this seems to work):

   //ADD ROW
   $("#add").click(function() {
  $("#rows").append(
    '<tr id="row3">'
    + '<td><input class="A"  /></td>'
    + '<td><input class="B"  /></td>'
    + '<td><input class="C"  /></td>'
    + '<td><input class="remove" name="remove" type="button"
value="-" /></td>'
    + "</tr>"
  );
  });

        //REMOVE ROW
        $(".remove").live("click", function() {
  $(this).parent().parent().remove();
        });

My problem is that while the calculation works on the first to default
rows, calculation doesn't seem to work on rows that I added by
clicking on add row-button.

Anyone know why is happening?

Re: AJAX is not invoked for dynamically added input fields

by Giovanni Battista Lenoci-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

palgo ha scritto:
> My problem is that while the calculation works on the first to default
> rows, calculation doesn't seem to work on rows that I added by
> clicking on add row-button.
>
> Anyone know why is happening?
>  
Do you use the live functionality also for the keyup event that will
fire the ajax call?

Bye

--
gianiaz.net - web solutions
via piedo, 58 - 23020 tresivio (so) - italy
+39 347 7196482


Re: AJAX is not invoked for dynamically added input fields

by palgo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks man!
So I changed this line to this to get it to work:

//old
$(".A, .B").keyup(function(event){ ....

/new
$(".A, .B").live ("keyup", function(event){...

Thanks again for your quick answer!

-Palgo

On 11 Nov, 14:27, Giovanni Battista Lenoci <gian...@...> wrote:

> palgo ha scritto:> My problem is that while the calculation works on the first to default
> > rows, calculation doesn't seem to work on rows that I added by
> > clicking on add row-button.
>
> > Anyone know why is happening?
>
> Do you use the live functionality also for the keyup event that will
> fire the ajax call?
>
> Bye
>
> --
> gianiaz.net - web solutions
> via piedo, 58 - 23020 tresivio (so) - italy
> +39 347 7196482