How to set value to global variable in jquery?
<p>I have a form</p>

<pre><code>  &lt;form method="get" id="searchform" &gt;
    &lt;input value="Search..." id="s" type="text"&gt;
  &lt;/form&gt;
</code></pre>

<p>and a jquery code</p>

<pre><code>&lt;script language="javascript"&gt;
    var searchformValue;
    $('#searchform').submit(function(){
        searchformValue = $('#s').val();
        return searchformValue;
        });

&lt;/script&gt;
</code></pre>

<p>but when i alert the search formvalue outside the function</p>

<pre><code>&lt;script language="javascript"&gt;
    var searchformValue;
    $('#searchform').submit(function(){
        searchformValue = $('#s').val();
        return searchformValue;
        });
            alert(searchformValue);

&lt;/script&gt;
</code></pre>

<p>it returns unidentified.Why??</p>

<p>Any solutions for it?</p>

<p>Edit: I want to have the searchformValue with the submit value after the function runs</p>
