Jump to content

Populate fields based on dropdown selection


mrnorx

Recommended Posts

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

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. 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.