I have a form for product advertisement. In there I have a field margin. basically I want to get data from margin field and plus the percent user entered with the market price. eg: 15% + current_market_price. then show the result back to user. I'm using php for the back-end and form validation. but I want to do this without hitting the submit form button. Is there any way to do this?
Asked
Active
Viewed 44 times
0
-
If you want PHP to do the calculation, then use AJAX to send the form data to your server which would do the calculation, then send back the result. The alternative is to use JavaScript directly to do the calculation and skip the server entirely. – waterloomatt Nov 20 '19 at 12:51
-
Possible duplicate of [form serialize javascript (no framework)](https://stackoverflow.com/questions/11661187/form-serialize-javascript-no-framework) – diogenesgg Nov 20 '19 at 13:36
1 Answers
0
You could use JavaScript. I don't think you can use PHP since it's server-side. You can still use php to validate the data, but you'll have to send the request in JS .

Yeonsan
- 11
- 5
-
I just started learning programming a month ago. so I don't know much about JavaScript. can you reference any guide or method I can learn. – Nov 20 '19 at 12:51
-
Oh, well. I suggest you start with the JavaScript basics. Any tutorial will do. Then some php tutorials on how to receive GET/POST requests the proper way. Finally there are some good libraries for sending http requests in JS. The easiest for beginners in my opinion is JQuery, which is also well documented. – Yeonsan Nov 20 '19 at 12:56
-
Ok thanks, I've learned php also build a cms system with procedural so I know how to send POST/GET requests and when to use them. anyway thank you! – Nov 20 '19 at 13:11