Jquery with boxy plugin – load and submit a form via ajax

jquery, jquery-plugins

I am using JQuery with Boxy plugin.

When a user clicks on a link on one page, I call Boxy.load to load a form onto the pop-up. The form loads and is displayed inside the pop-up without problems.

However, I can't bind the form to a submit event, since I can't select the form element.

This is the event handler:

    $('#flag-link a.unflagged').click (function(e) {        url = $(e.target).attr('href');        Boxy.load(url, {behaviours: function(r) {            alert ($("#flag-form").attr('id'));            }        });    });

The alert reads "undefined" when it is displayed.

And this is the form:

<form id="flag-form" method="POST" action="somepage">            <table>        <tr><td><input type="text" name = "name"></td></tr>        <tr><td><input type="submit" value="OK"></td></tr>    </table></form>

What am I doing wrong?

Best Solution

First (a minor point, but a potential source of trouble), it should be id="flag-form" not id = "flag-form" (no spaces).

Second, you shouldn't need r.find(). Just do $("#flag-form").attr("id")