javascript function works until it is moved into a .js file
<p>I have a question about placement of javascript.</p>

<p>The function nqi_search works fine when it lives outside of a.js file. 
It fails, without errors, if it is moved into  my1.js, before the jquery files, or into my2.js after the jquery files. I've had similar problems before. Are there rules about what can and cannot go into .js files, and the order of .js files?</p>

<p>nqi_search is called within the jQuery ready function.</p>

<pre>
&lt;script type="text/javascript" src="javascript/my1.js"&gt; &lt;/script&gt;
&lt;script type="text/javascript" src="javascript/jquery.js"&gt; &lt;/script&gt;
&lt;script type="text/javascript" src="javascript/jquery-ui.js"&gt; &lt;/script&gt;
&lt;script type="text/javascript" src="javascript/my2.js"&gt; &lt;/script&gt;


&lt;script type="text/javascript"&gt;
function nqi_search (type, id_name, text_name)
{
    $(function() {
        function store_id( id ) {
            $( "#"+id_name ).val(id);
        }

        $( "#"+text_name ).autocomplete({
            source: "remote.php?f=nqi_search&t="+type,
            minLength: 1,
            select: function( event, ui ) {
                store_id( ui.item.id );
            }
        });
    }); 
}
&lt;/script&gt;

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function() {

    nqi_search ("product_search", "product_id", "product_name");    


});
&lt;/script&gt;
</pre>
