javascript how to dynamically update a variable
<p>I have an html form that triggers a function to change a value, reference: <a href="http://jsfiddle.net/ZvuMh/3/" rel="nofollow">http://jsfiddle.net/ZvuMh/3/</a> 
How can I use <code>avalue</code> dynamically in another function?</p>

<p>HTML:</p>

<pre><code>&lt;select id="sort_post_date"&gt;
    &lt;option value="a"&gt;a&lt;/option&gt;
    &lt;option value="b"&gt;b&lt;/option&gt;
    &lt;option value="c"&gt;c&lt;/option&gt;
    &lt;option value="d"&gt;d&lt;/option&gt;
    &lt;option value="e"&gt;e&lt;/option&gt;
    &lt;option value="f"&gt;f&lt;/option&gt;    
&lt;/select&gt;​
</code></pre>

<p>Change value function:</p>

<pre><code>    var avalue='';
function getSelectData(id) {


    // set value to be the current selected value
    avalue = jQuery(id+" option:selected").val();

    // change value whenever the box changes
    jQuery(id).change(function () {
        avalue = jQuery(id+" option:selected").val();
        console.log("I see a change! -&gt; "+avalue);
    });

    console.log(avalue);
    return avalue;
}

var d = getSelectData("#sort_post_date");
console.log(d);​
</code></pre>

<p>Another function that wants to inherit <code>avalue</code> when function getSelectData changes it to another letter:</p>

<pre><code>function somefunction(){
    var test = "foo"+avalue;
}
</code></pre>
