General jquery function for form submission
<p>I have this small tabbed system developed in PHP/JavaScript.</p>

<p>For form submissioni, I bind a JQuery function to the 'submit' event that sends an Ajax query to the server, avoiding to reload the page (and losing other tabs). I have coded one function for every form, but realized that they are the same (take the inputs, send the Ajax query, show the returning message) so I decided to make a general jquery function with arguments that define each form).</p>

<p>I have this function:</p>

<pre><code>function submit_search(entity){
        $('#'+entity.name+'_searchform').submit(function(){
            var url = public_path+entity.name+'/search';
            var key = $('#'+entity.name+'_search_key').val();

            $.ajax({
                type: 'POST',
                url: url,
                data: {search_key: key},
                success: entity.submit_search(result)
            }); 

            return false;
    });
}
</code></pre>

<p>Where <code>entity</code> is a JS object with the name of the entity and the success function I want to execute. This function is written in a script that loads once when the main page is loaded. And when the tab is loaded, I simply call <code>submit_search()</code> with the actual entity.</p>

<p>This seems logical to me. But it doesn't work. And the problem is that jquery doesn't recognize the elements, by example, after <code>var key = $('#'+entity.name+'_search_key').val();</code>, key is null.</p>

<p>What am I doing wrong?</p>
