Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1064499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:56:54+00:00 2026-05-16T18:56:54+00:00

I have a form which contains a select named Client_ID as well as some

  • 0

I have a form which contains a select named Client_ID as well as some other text inputs. What I need is that when a user selects a Client_ID, my fields Address1, Address 2 etc should be populated with the result of a database query along the lines of

SELECT Address1, Address2 from Client where Client_ID = Client_ID

I’m aware this is somewhat of a noob question, but would really appreciate some help on the simplest and best way to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:56:54+00:00Added an answer on May 16, 2026 at 6:56 pm

    You should do something like this with jQuery + JSON

    First of all download jquery from here and include it in your application.

    If home.php, your downloaded jquery file(jquery-1.4.2.min.js) and getData.php are in the same folder then your home.php will be look like this:

    home.php (file that contain your form)

    <html>
    
    <head>
    
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
    
        <script type="text/javascript">
        jQuery(document).ready(function(){
            jQuery('#Client_ID').live('change', function(event) {
                $.ajax({
                    url     : 'getData.php',
                    type    : 'POST',
                    dataType: 'json',
                    data    : $('#myform').serialize(),
                    success: function( data ) {
                           for(var id in data) {        
                                  $(id).val( data[id] );
                           }
                    }
                });
            });
        });
        </script>
    
    </head>
    
    <body>
    
        <form id='myform'>
         <select name='Client_ID' id='Client_ID'>
           <option value=''>Select</option>
           <option value='1'>Client 1</option>
           <option value='2'>Client 2</option>
         </select>
    
         <input type='text' name='address1' id='address1'>
         <input type='text' name='address2' id='address2'>
    
         <select name='gender' id='gender'>
            <option value=''>Select</option>
            <option value='1'>Male</option>
            <option value='2'>Female</option>
         </select>
    
        </form>
    
    </body>
    
    
    </html>
    

    getData.php

    <?php
    
    $clientId = $_POST['Client_ID']; // Selected Client Id
    
    $query  = "SELECT Address1, Address2 from Client where Client_ID = $clientId";
    $result = mysql_query($query);
    $row = mysql_fetch_array($result, MYSQL_ASSOC)
    
    $add1 = $row[Address1];
    $add2 = $row[Address2];
    $gender = 1;
    
    $arr = array( 'input#address1' => $add1, 'input#address2' => $add2, 'select#gender' => $gender );
    echo json_encode( $arr );
    
    ?>
    

    I have tested this code on my machine and it is working.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed to create a custom select list for the user registration page that
I have a form like this: class MyForm(forms.Form): [...] which is rendered in my
I have a strongly typed view of type ProductListingViewModel which in turn contains a
I have a form inside an iframe which is inside a jQuery UI dialog
I need to sort on a date-field type, which name is mod_date. It works
I'm writing a semi-generic form plugin using jQuery in order to speed up the
As my Rails app matures, it's becoming increasingly apparent that it has a strong
I've been assigned the task to design a temporary customer tracking system in MS
i am using the Jquery validation plugin, sourced from here . It is function
I would like to know people's thoughts on the best way to do the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.