If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How can I do this with javascript?

I have a PHP form that has a drop down menu (to select CAR) and one input box (for quantity) and button to calculate total price (quantity x price). When a visitor selects a car I need to picks up value for price from the same MySQL tables.

This is while the visitor is still on the same page (before he click on calculate total button), so it can not be done with PHP. How do I do this with Javascript?
It seems like a simple task but I am very new with js and can not think of a way to access the database without including password and other information for database in the javascript whch can be seen in source code and is a security issue.
any suggestions or help is greatly appreciated.
Thank you in advance
JayJava

You'll need to make a PHP page that picks up a variable given by POST or GET and queries the database for the value, then echoes out the value, then you'll need to use AJAX in the JavaScript to send the car the user chooses to that PHP page, the value will then be returned in the AJAX response.

My code

Thank you iBeZi for trying to help.
I guess I am too ignorant of JS to understand what you mean.
I include my code here maybe you can tell me if what I am trying to do is possible with your method or not?

This form in on a page called cars.php and after visitors select three cars and enter the quantity for each I need to pick up price of each car from mySQL database and do a calculation to get total, show it in the text box bellow.
Then the user clicks on the save button and information is sent to another php page that saves it.

problem is that I can not run a querry on MYSQL with PHP and show in the same page before users go to save , that's why I am trying to use javascript.
What do you think?
thanks a million in advance.
Jay

You can't access a MySQL database directly through JavaScript, you have to use AJAX to get content from another page asynchronously (without reloading the page), you have to make a PHP page which you'll send the selected cars to through AJAX to get the prices, you could even do this and get the total price directly from the PHP page like this.

Thank you

Thank you IBiZi you re a great help eveytime I post a question.
I was doing some search regarding this problem and came across some videos on youtbe showing how to use jquery.js library to do this. What do you think about jquery?

I repeated the experimen they where doing. The thing works but here is no reference or call to any functon as far as I can tell. Any iea as why this should work?

There are two pages data.php and index.php. Visitor sees only the index.php page.

I'm honestly not a fan of JQuery, I avoid it whenever I can, it's a huge and very powerful library, but it's unnecessary unless you need to use it a lot. It works by taking loads and loads of JavaScript features and hiding them behind functions within the JQuery library to make it easier to use them, you can do most things without it though.

Without JQuery the test you've made here would look a little something like this.