Log in

View Full Version : Resolved prepopulate a drop down list from sql database



mcolton
01-09-2010, 12:31 PM
I have a form with a drop down list. Some of this form has been prepopulated with data from a mysql database. Everything else is working except I don't know how to prepopulate the drop down list.
I hope I explained this right.

Example:
Drop down list options: 1, 2, 3, 4, 5
data from mysql: 3
So when the user gets to the drop down list, he sees 3 selected and he can then change it
Thanks for any help

djr33
01-09-2010, 07:30 PM
Looks like this was solved. For anyone else with a similar question, here are the basic steps:
1. Use PHP or another server side language to gather the relevant information from the database.
2. Use that language to then output the TEXT of the javascript for the dropdown menu, such as:
echo 'mymenu[] = "item1";';
(repeat for each item).
3. Then Javascript will have the information when the page loads.

(Remember: there is no easy way to get the data using Javascript, so "prepopulating" it is the best approach.)