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 8677805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:33:26+00:00 2026-06-12T20:33:26+00:00

html <input type=text name=PName /> <input type=text name=PAddress /> <input type=text name=PCity /> mysql

  • 0

html

<input type="text" name="PName" />
<input type="text" name="PAddress" />
<input type="text" name="PCity" />

mysql table

 ________________________________________________________
| id  |PName          |  PAddress           |  PCity    |
| ----|-------------------------------------------------|
|  1  | John           |  po box no xyz      |  Florida |
?????????????????????????????????????????????????????????

now my question is how do i use ajax to fetch the address and city when i enter the name? any help is appreciated

  • 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-06-12T20:33:27+00:00Added an answer on June 12, 2026 at 8:33 pm

    A while ago, i did a “live” search for my project, so here is some code modified for your needs (i assume you have jQuery on your page).

    First of all i suggest you give your inputs some id’s:

    <input type="text" name="PName" id="PName" />
    <input type="text" name="PAddress" id="PAdress" />
    <input type="text" name="PCity" id="PCity" />
    

    After that you can bind a keyup event of PName field:

    var searchTimeout; //Timer to wait a little before fetching the data
    $("#PName").keyup(function() {
        searchKey = this.value;
    
        clearTimeout(searchTimeout);
    
        searchTimeout = setTimeout(function() {
            getUsers(searchKey);    
        }, 400); //If the key isn't pressed 400 ms, we fetch the data
    });
    

    The js function to fetch the data:

    function getUsers(searchKey) {
        $.ajax({
            url: 'getUser.php',
            type: 'POST',
            dataType: 'json',
            data: {value: searchKey},
            success: function(data) {
                if(data.status) {
                    $("#PAddress").val(data.userData.PAddress);
                    $("#PCity").val(data.userData.PCity);
                } else {
                    // Some code to run when nothing is found
                }   
            }
        });         
    }
    

    And ofcourse the getUser.php file:

    <?php
        //... mysql connection etc.
    
        $response = Array();
    
        $response['status'] = false;
    
        $query = mysql_query("SELECT `PAddress`, `PCity` FROM `Users` WHERE `PName` LIKE '%".$_POST['value']."%' LIMIT 1"); //Or you can use = instead of LIKE if you need a more strickt search
    
        if(mysql_num_rows($query)) {
            $userData = mysql_fetch_assoc($query);
    
            $response['userData'] = $userData;
            $response['status'] = true;            
        }
    
        echo json_encode($response);
    

    Good luck! ^^

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

Sidebar

Related Questions

I have the following HTML: <input type=email id=email> I want to type text into
I have a form with different html input fields... 1) <input type=text> 2) <textarea></textarea>
I want to use the placeholder attribute for HTML input[type=text] elements such that the
Is there a simple way to upload a single file through HTML input type
HTML has an input button type to reset all fields in a form to
I have an input on an HTML page where a person will type something
html structure: <form method=post id=comment-form accept-charset=UTF-8> <div class=form-item form-type-textfield form-item-name> <input type=text id=edit-name name=name
I have a html input control within a asp:UpdatePanel and I have its associated
I have a page with File html input field and a Submit button as
I have always and will continue to always close an HTML input such as

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.