Passing a variable into a form loaded into a dialog

Passing a variable into a form loaded into a dialog

I've made a made a lovely form which is loaded into a dialog upon clicking a link. Works fine, but I want something which identifies they URL clicked on initially (e.g. /stats.php?id=bob ) to end up as a hidden form field. Should be easy but I can't get the syntax/logic right.

This code creates the dialog and loads the form:

  1. <script type="text/javascript">
    $(document).ready(function() {
        $('div.subscription a').each(function() {
            var $link = $(this);
            var $url = $link.attr('href');
            var $dialog = $('<div></div>')
                .load('subs_form2.php')
       
                .dialog({
                    autoOpen: false,
                    title: "eNews subscription",
                    width: 600,
                    height: 460,
                    modal: true
                });

            $link.click(function() {   
                $dialog.dialog('open');

                return false;
            });
        });
    });

    </script>
























and this bit should retrieve and append ...

  1.   $(document).ready(function() {
                $('#subs_form').append('<input type="hidden" name="url" value="'+ url +'" />')           
                        .validate({ etc ....





Not only does it not append but it breaks the validation code following.

Any help appreciated