views:

19

answers:

1

I have the following:

$(document).ready(function(){
    // bind 'myForm' and provide a simple callback function 
        $('#form').ajaxForm(function() { 
            alert("Works!!!"); 
        });                        
});

The problem is that when I dynamically add the form to the HTML the script is not working. If the form is there from the beginning the form is submitted with Ajax and works as expected. What is the problem here?

+1  A: 

the problem is that $(document).ready() only gets fired when the page is initially loaded. If you add the form dynamically to the page, you'll need to make the call to setup the form again.

Alternatively, you can use the livequery plugin to 'listen' on the page for when a new form element is added to the page and to automatically setup the form for you.

lomaxx