Returning a result
<p>I want a JavaScript function that posts to a php, and returns the value, so that calling the function from another function in JavaScript gives me the value. To illustrate better please look at my current code:</p>

<pre><code>function sumValues(number1, number2) {
    var return_val;
    $.post("sum_values.php", {number1: number1, number2: number2},
    function(result) {
        return_val = result;
    });

    return return_val;
}
</code></pre>

<p>However, the above is returning undefined. If I put <code>alert(result)</code> inside the <em>function</em> part in <code>$.post</code>, I can see the result. However if I call the function from another JavaScript file the return value return_val is 'undefined'. How can I put the result from <code>$.post</code> inside <code>return_val</code> so that the function can return it? </p>
