Function calls in modal dialog

Function calls in modal dialog

Hi,

I have a modal dialog with the functionality inside to add new form fields to the form in the dialog by clicking on a button in the dialog. This works fine on the first opening of the dialog. If i close the dialog and reopen it again, without refreshing the page, the function to add new form fields doesn't work anymore. My function looks like the following:

  1. $('.addproductbutton').click(function(event) {
  2.         var count = $('#fieldset-products > *').length
  3.         $.ajax({
  4.             type: "get",
  5.             url: "/addproduct/count/"+count,
  6.             contentType: "application/json; charset=utf-8",
  7.             dataType: "json",
  8.             success: function(result) {
  9.                 $('#fieldset-products').append(result.html);
  10.             },
  11.         });
  12.     });
Can it have something to do with the ids of the dom objects ?
Some ideas how to solve this ?

Thanks in advance.