List/Menu posts value in text box

I am fairly new to PHP and MySQL…
I am using:

[ul][li]Dreamweaver CS4[/li]
[li]WAMP[/li][/ul]
I have created a static website and need to implement dynamic elements.
I have accomplished some of these things using a JavaScript show/hide element.
But… I feel everything would work much better if I use PHP and MySQL…
So I have endeavored to learn some PHP and MySQL…

So far I have learned:

[ul][li]How to retrieve my data from my Excel spread sheet and import it using PHP MyAdmin…[/li]
[li]How to import the data into tables, text boxes, and list/menu on my website…[/li]
[li]How to set up a login/password system for users.[/li][/ul]
I have several things I need to learn still…

I feel the next step is that I need to learn how to set this up:

[ul][li]User selects item from a list/menu…[/li]
[li]Value of selection displays in a text box…[/li][/ul]

For example:
User selects ball (which is the item)from list/menu…
And ? $2.50 (which is the value) displays in the text box.

All of the data for item and value is coming from the database.

I have looked all over for a tutorial to learn how to do this and have come up with nothing.
Can someone please point me in the right direction… Where I can learn how to do this… Some tutorial or something.

All help is MUCH appreciated! ;D

Such dynamic interaction as you need (i.e. pick an item in select box, and have textbox populated with price) can be achieved with javascript. If you only use PHP, the page will have to reload to display price.

When generating html page with PHP, you can read products (such as ball) from your MySQL database table, and populate options to your element. Then, to display price, you can do b[/b] use Ajax, that will request php script from server, that will query MySQL database for price for that product, or b[/b] create hidden form fields where you will store array of prices - and again use Javascript to populate textbox when corresponding product is selected.

Thanks for the help. :slight_smile:
If I understand what you are saying I don’t think that b) would be the direction I need or want to go.
My understanding of b) is to continue to use the JavaScript show/hide code to show/hide a text box with each relevant value when item is selected. That would require creating ten million little text boxes with value in them… :o
If that is not what you are saying and there is a way to use one text box that you show/hide and can call the values from the database that correspond with the item selected… Then can you point me to a tutorial or something because I am coming up with nothing…

I did find a tutorial using the AJAX… though I have never worked with AJAX before… :-\

Using ajax is working so far. ;D
It was fairly simple to figure out and apply the concepts learned for what I needed.

Just in case any one else would like to know…
Here is the tutorial I used.
http://www.tizag.com/ajaxTutorial/ajax-mysql-database.php

Again much thanks… for the tip on Ajax… ;D
I figured it was something “simple” enough to figure out…
But I was stumped…

It’s usually simple little things that give me the biggest headaches…

Sponsor our Newsletter | Privacy Policy | Terms of Service