PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Yes, with AJAX: you send a HTTP request to your PHP script, make it do the calculations, have it return the result, and make your Javascript deal with the result however you want.
But needless to say, that's completely ridiculous for just simple arithmetic.
...Kinda. Do the calculation in the form so that the user can see what's going on, but make your PHP script do the calculation itself. A second time.
Why? Because what happens in the browser is completely under the user's control. Like me, if I were using your site. I could make it do whatever calculations I wanted and then send that data to your script. That's why your script has to do the calculation too: to make sure it has the right figures and to make sure I can't cause something to happen that shouldn't.
Classic example is on a shopping cart and adjusting item totals with Javascript. If I want two items then go ahead and show me the original price *2, but don't actually use that particular number to decide the total price. Otherwise I could just make it "calculate" $0.00 and get your stuff for free.