mrnorx Posted May 10, 2011 Share Posted May 10, 2011 Hi, I am a bit of novice when it comes to php and javavscript but am learning as I go and new problems face me. I have an SQL database table called groups with 3 fields (Name, Number, Email). I have a form with a dropdown which populates with data from the name field ( I managed to this with a code snippet I found on google). What I need is for 2 text fields in the from called number1 and email1 to poulate from the database when the user selects a name from the dropdown. For example user clicks on John in the dropdown then a database query looks up john and returns the number and email into the 2 relevant fields. I know I need to use the onchange statement to call the script, Ive read the tutorial on http://www.w3schools.com/PHP/php_ajax_database.asp but this uses AJAX to create a table and I want to just populate form text fields which I assume should be easier. Can anyone show me the script I need to use? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/236015-populate-fields-based-on-dropdown-selection/ Share on other sites More sharing options...
gizmola Posted May 11, 2011 Share Posted May 11, 2011 First create a script that accepts name as a parameter, queries the groups table and returns the name, number and email. Most people these days will use json format for the data. When you have that done, you can do the ajax, and the DML should be simple enough, but I strongly suggest that you use jquery rather than trying to adapt some crappy w3schools article. Quote Link to comment https://forums.phpfreaks.com/topic/236015-populate-fields-based-on-dropdown-selection/#findComment-1213668 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.