views:

13

answers:

1

I'm using a modal plugin (colorbox) that has an option "onComplete". I can do the following to achieve part of the effect I'm going for (this is just the "onComplete" option):

onComplete: function(){
$('.ajaxform').ajaxForm({
            success: function(responseText){
                $.colorbox({html:responseText});
            }
        });
}

The reason is that the modal loaded through ajax contains a form. That form uses ajaxForm() to submit and the modal is changed to reflect the responseText. It works great (for the first form). But the problem is that I have several forms in a row. What's a good way to attach the 'ajaxForm()' and still use the $.colorbox({html:responseText}) to many forms? I'd like to do this for an unspecified number of forms (in other words, in the code I can't write it thinking I have 4 forms, because maybe I'll later have 5 or 3 or something)

A: 

Just define your "onComplete" as a standalone function:

function completeHandler() {
  $('.ajaxform').ajaxForm({
    success: function(responseText) {
      $.colorbox({html: responseText, onComplete: completeHandler});
    }
  });
}
Pointy