Instant field validation calling for database

I have a data entry form with many fields in it. Some of the fields need to be validated instantly before submission of the form. These validations imply retrieval of some data from some other tables. The data retrieved must then be used in some calculation the result of which will be used as a content by default of some other fields of the form.

I need this for an invoicing module: When the user inputs the code of the product purchased and the quantity, the product’s price needs to be retrieved instantly from the product table so that the total price to be paid may be calculated. This information must then be automatically displayed in the ‘total price’ field on the form.

Could someone help me? I do not quite have an idea where to look for help. As far as I know, Javascript cannot interact with the database.

Create a controller/action taking the product code as parameter, performing the needed calculation, and returning the result. That action would of course be called by ajax, and you chose your event, onBlur, or when a "refresh" button is clicked, whatever.

If what I say is obscure to you, you may want to see the logic of dependent dropdown:

If it’s still obscure :slight_smile: get back to us

Thanks for your prompt reply. I do not quite know ajax (I am quite new to php and am trying to learn everything rapidly and this forum is of great help to me) but I understand what you are saying. I will try to work out on it and get back if I do not succeed.