 <p>You cannot place <code>myFunction</code> after the <code>onclick</code>. When the <code>onclick</code> is seen there is no definition for <code>myFunction</code>. </p> <p>Place the JavaScript in <code>&lt;head&gt;</code> tag. Also, move the function outside of <code>ready()</code>.</p> <p>Like this:</p> <pre><code>&lt;script type="text/javascript"&gt; var nexturl =""; var lastid =""; var param; function myFunction() { param = $('#search').val(); alert("I am an alert box!"); if (param != "") { $("#status").show(); var u = 'https://graph.facebook.com/search/?callback=&amp;limit=100&amp;q='+param; getResults(u); } } $(document).ready(function() { $("#more").click(function () { $("#status").show(); $("#more").hide(); pageTracker._trackPageview('/?q=/more'); var u = nexturl; getResults(u); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; ... </code></pre>