Page 1 of 1

No refresh Calulator-Simple

Posted: Fri Nov 25, 2011 7:20 pm
by nite4000
Hey all I am not sure this is the right place to post this so if its not I apoligize but here is what I am trying to do.

I have a form

<form action="calc.php" method="post">
<table>
<tr><td width="48">Amount</td><td width="128"><input name="amt" type="text" value="<?php echo $_POST['amt']; ?>" size="8" maxlength="8" /></td></tr>
<tr><td>Percent</td><td><input name="per" type="text" value="<?php echo $_POST['per']; ?>" size="8" maxlength="8" /></td></tr>
<tr><td><select name="days">
<option value="daily" selected="selected">Daily</option>
<option value="after">After</option>
</select></td><td><input name="days2" type="text" value="<?php echo $_POST['days2']; ?>" size="8" maxlength="8" />
days</td></tr>
<tr><td colspan="2"><input name="go" type="submit" value="Calculate" /></td></tr>
<tr><td>Total</td><td><?php echo $total;?></td></tr>


</table></form>


which is basic table as you see now i have this as php code at the top

Code: Select all

<?php

if(isset($_POST['go'])) {
	
	if($_POST['days'] =='daily') {
$total = $_POST['amt'] * $_POST['per'] / 100 * $_POST['days2'];	
	}

	if($_POST['days'] =='after') {
$total = $_POST['amt'] * $_POST['per'] / 100 * 1;	
	}

}


?>

My task is I need to submit this to get the results WITHOUT refreshing I have read its jquery and JS but I am lost when it comes to this. I have looked at samples but no luck any help would be nice.

Thanks

Re: No refresh Calulator-Simple

Posted: Sat Nov 26, 2011 4:18 am
by mikeashfield
You sure wouldn't want to use JQuery for this, as there's no communication to the server necessary as far as I can see. The client-machine is more than capable of performing mathematics, so let it. Just embed a JS calculator from one of many thousands of sources on google.