Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.