No refresh Calulator-Simple

JavaScript and client side scripting.

Moderator: General Moderators

No refresh Calulator-Simple

Postby nite4000 » Fri Nov 25, 2011 8:20 pm

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


Syntax: [ Download ] [ Hide ]
<?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
nite4000
Forum Contributor
 
Posts: 206
Joined: Sun Apr 12, 2009 11:31 am

Re: No refresh Calulator-Simple

Postby mikeashfield » Sat Nov 26, 2011 5:18 am

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.
mikeashfield
Forum Contributor
 
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am


Return to Javascript

Who is online

Users browsing this forum: No registered users and 1 guest