First of all let me say that I’m just starting to learn, as a hobby, the basics of Web development: html, css, javascript and php.
I’m trying to implement a Web page with a database query and have encountered some dificulties:
If someone could enlighten me on which way to proceed it would be much appreciated.
I don’t want you to write the whole code for me but yes show me some hints and clues.
I have a table with Id, items, price1, price2, and price3.
After a lot of searching I managed to load all the items dynamicaly on a select list and show (price1) on a div with an on change event based on the item selected with an ajax call.
Now I need to update this price div based on two other select lists: one with 3 values (a,b,c) and the other one with (yes or no).
If select list 2 is (a) and select list 3 is (yes) the price to be displayed is (price2); If select list 2 is (b) and select list 3 is (yes) the price to be displayed is (price3) and if select list 3 option is (no) than wich ever price was loaded must be dobled. All with ajax and regardless to the order of selections.
Hope I made myself clear. I can load my code if needed.
Thanks for the reply.
You got the logic right.
So far I only have working the ajax call to display price1 based on item select list.
Do I have to build one ajax call for each of the other select lists?
Do I make the if conditions in the js file or in the server side php?
Thanks again.
I’m not big on Ajax, but I’d think you could call the same browser code, which would then assemble the settings of all the selections to pass them in to the PHP code. In fact as the data coming back relies on all settings, I would imagine you’d have to do it that way. Or possibly you could return price2 and price3, and have the JS function that executes on return decide which one to display, and whether or not to double it. I think it would be neater to do that on the server side, but that’s just me.