mikevarela Posted January 8, 2010 Share Posted January 8, 2010 Making a calculator and would like the submit button to calculate and post back the answer to the same page. In the below example I get the answer on a cleared out page. I kinda want to do this AJAX style but use PHP.. is there any way to handle this? <?php $sampleRate = $_POST['sample_rate']; $bitDepth = $_POST['bit_depth']; $channels = $_POST['channels']; $timeSeconds = $_POST['time_minutes'] * 60; // Sample Rate X Bit Depth $sampleBit = $sampleRate * $bitDepth; // multiply number of channels $sampleBitWithChannels = $sampleBit * $channels; // Convert To Bytess $bytes = $sampleBitWithChannels / 8; // Add Seconds $bytesSeconds = $timeSeconds * $bytes; // get MB figure $MB = ($bytesSeconds / 1024) / 1024; if(! $_POST['calculate']) { ?> <html> <head> <title>Calculate File Size</title> </head> <body> <form method="post" action=""> <fieldset> <legend>File Size Calculation</legend> <table> <tr> <td> Sample Rate </td> <td> <select name="sample_rate" id="sample_rate"> <option>32000</option> <option>44100</option> <option>48000</option> <option>88100</option> <option>96000</option> <option>192000</option> </select> </td> </tr> <tr> <td> Bit Depth </td> <td> <select name="bit_depth" id="bit_depth"> <option>8</option> <option>12</option> <option>16</option> <option>24</option> </select> </td> </tr> <tr> <td> Channels </td> <td> <select name="channels" id="channels"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> </select> </td> </tr> <tr> <td> Time in Minutes </td> <td> <input type="text" name="time_minutes" id="time_minutes" size="5" /> </td> </tr> <tr> <td> <input type="submit" name="calculate" id="calculate" value="calculate" /> <input type="reset" value="reset" /> </td> </tr> </table> </fieldset> </form> <h3>Common Standards</h3> <table border="1"> <tr> <td>Compact Disc</td> <td>Movie</td> <tr> <tr> <td>44.1kHz / 16bit</td> <td>48kHz / 24bit</td> </tr> </table> </body> </html> <?php } else { echo '<p>Your Value is: ' . round($MB) . ' MB</p>'; } ?> Link to comment https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/ Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 This is totally possible with AJAX. AJAX uses php or another server side language to get data. You tell your php script how to format the data, your javascript calls the code, gets the data back and uses the formatted data Link to comment https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/#findComment-991061 Share on other sites More sharing options...
mikevarela Posted January 8, 2010 Author Share Posted January 8, 2010 right, any code help though on how to handle this? Link to comment https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/#findComment-991080 Share on other sites More sharing options...
JAY6390 Posted January 8, 2010 Share Posted January 8, 2010 Not sure on your current AJAX abilities, but this is a good site to learn it http://www.deathmonkeyz.com/tutorials Link to comment https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/#findComment-991082 Share on other sites More sharing options...
gerardcorr Posted January 8, 2010 Share Posted January 8, 2010 have a look at mootools http://www.mootools.net. Make ajax really easy Link to comment https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/#findComment-991185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.