How would I do this in PHP? Form input, then function, then output in div, without page refresh?
<p><strong>index.php</strong></p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Form submit in php without refresh?&lt;/title&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
function processForm() { 
        $.ajax( {
            url: process.php,
            data: 'how to get everything from process.php echos?',
            success: function(data) {
                $('#calc').html(data);
            }
        } );
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form" method="post" action="" onsubmit="processForm();return false;"&gt;
        &lt;input type="text" id="total" name="total" value="" /&gt;
        &lt;input type="submit" value="Submit" id="submitButton" /&gt;
    &lt;/form&gt;
&lt;div id="calc"&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>process.php</strong></p>

<pre><code>&lt;?php
$number = $_POST['total'];
//this should be $number = "the number entered in the 'total' field in the form";

echo $d = ceil(log(2*$number)/log(3))," tiers&lt;br /&gt;\n";
$x = 1;
for($i = 1; $i&lt;$d;$i++){
    echo "tier " . $i . "&lt;br /&gt;\n";
    echo str_repeat('o', $x),"&lt;br /&gt;\n";
    $number -= $x;
    $x *= 3;
}
echo "tier " . $i . "&lt;br /&gt;\n";
echo str_repeat('o', $number),"&lt;br /&gt;\n";
//all of the above echos should go into the 'calc' div in html, without page refresh
?&gt;
</code></pre>
