Jump to content

fill in the adjustment automatically?


arn_php

Recommended Posts

I am working on this form where (I want to be) if you put a number to the amount field, the amount adjustment field would automatically calculate the number to add the 3% adjustment.  Here is the code:

 

Amount: <input name="amount" type="text" value="<?=stripslashes($_POST['amount']);?>" size="5" />

<?php

$amount = $_POST['amount'];

$total = $amount * 1.03;

?> 

Amount Adjustment:  $US <?php echo $total; ?>

 

But then this is only works if I click the submit button.  I want it calculate directly after I fill the number into the amount field before clicking the submit button.  How to do that?

Link to comment
https://forums.phpfreaks.com/topic/136782-fill-in-the-adjustment-automatically/
Share on other sites

Use javascript. PHP can only be executed on the server, and while an Ajax call could be used to run a PHP script that multiplies account by 1.03, it would seem a bit excessive using Ajax for something like this when it can easily be done using javascript

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.