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

Link to comment
Share on other sites

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. 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.