views:

81

answers:

1

I've create code to add table row with formfield, and try to bind the 3rd party suggestbox function the each dynamic generate formfield

<script type="text/javascript"> 
$(document).ready(function() {
 $('#form1').validationEngine();
 var newRowNum = 1;
 $(".addRow").click(function(){
  var $newTr = $("#tb1 tbody>tr:last").clone(true);
  $newTr.find('input[id^=foods]').unbind(jsonSuggest());  <== try to unbind the previouse jsonsuggest()
  //$newTr.find('.jsonSuggestResults').remove();
  $newTr.appendTo("#tb1 tbody");
  $('input[id^=foods]', $newTr).val('');
  $newTr.find('input[id^=foods]').each(function(){
   $(this).jsonSuggest(
     function(text, wildCard, caseSensitive, notCharacter) {
      rez = $.ajax({ 
       type: 'GET', 
       url: 'getFoodJSON.jsp',
       data: 'foods=' + text,
       dataType: 'json', 
       async: false 
      });
      return eval(rez.responseText); 
      },
      { ajaxResults:true 
      });
  });
  $newTr.find('input[id^=supplyDate]').each('id', function(){
   $(this).datepicker({dateFormat:'yy-mm-dd'});
  });
 });
});

however, the suggestbox accumulatived, here is the result I input something at row 7... link text Would you mind to tell me how to unbind the applied function at previous row+formfield? Thank you.

A: 

By writing unbind(jsonSuggest()), you are calling jsonSuggest and unbinding the value that it returns. Unless the jsonSuggest function is a generator that returns a handler method (which it probably isn't), that's not what you want. If it is, that's still not what you want, unless it returns the same handler every time.

You want (I assume) to unbind the jsonSuggest function itself by writing unbind(jsonSuggest), without parentheses.

SLaks