Personal Loan - Remortgages - MPAA - Debt - Project cars

PDA

View Full Version : How to populate a text box with data....


karfeef
May 9th 2007, 2:37 am
Hi all. new member and fairly new to php/mysql. i wonder if someone can help.

i am trying to create a simple form, with a single drop down list, populated from column 1 of a mysql table. what i need to happen is when an item is selected from the list, the text box underneath populates with the data from the same row in column 2 of the table, then the value of the textbox is posted to another table (but i already have that bit as i'm modifying an existing form) i just can't figure it :eek:

it can happen either from the selection event or by using a button

can anyone help? many thanks

Karf

NoamBarz
May 9th 2007, 8:21 am
You'd have to either repload the page or use ajax. The event you are looking for is: <select name='whatever' onchange='captureEvent()'>

To learn more about ajax, try this url: http://www.mousewhisperer.co.uk/ajax_page.html

If, on the other hand you want to reload the page, you'd have to select the data from your table using a select statement.

Ajax is very common today.

lemaitre
May 9th 2007, 9:36 am
This is not hard at all. In your PHP script, use the result set from the database query to write a Javascript associative array which maps the values from column 1 to values in column 2. Write the dropdown values as usual. Then go to the Javscript forum and ask for help writing a function that fills in the text box from column 2 of the array.

gibex
May 10th 2007, 6:56 pm
ajax is for advanced user, karfeef is new on js field.
a very good js resource to read is http://www.quirksmode.org/js/contents.html

karfeef
May 11th 2007, 2:08 am
Thank you all. looks like i need to crack on with some reading =)