auto complete textbox value from input of another texbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddsal
    New Member
    • Dec 2011
    • 8

    auto complete textbox value from input of another texbox

    i have a form which includes an id textbox and a name textbox.

    how do i implement it when i will input a id which is integer and a corresponding name to that id in the databases automatically inputs in the name textbox as well?

    i want to implement it in a oop approach so i have a class which will contain my function to query the database

    and a have a form.php
    and the action.php

    can anybody help me, i've know that this will probably be using ajax or javascript
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    you can send an ajax request on key press but, it is better to send an ajax request to server on change.

    You simply can do that
    1. Send an Ajax request to server with ID as value.
    2. Server will reply with name or failure request(id may not exists)
    3. on server reply change the the desired text box.
    use JQuery, it will make your life easier

    Comment

    • jeddsal
      New Member
      • Dec 2011
      • 8

      #3
      can you give me a very simple example on how to do this??pls. im not really familiar yet on how ajax works, i would really appreciate it.

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        Code:
        <script>
        
        function GetName(obj)
        {
        $.ajax({url: "getName.php", //the php file that will do the query and  give the name
        type: 'POST', //the method you would use, not a big deal in some case, can be a huge deal in some case.  
        dataType: 'html', 
        data: "Id="obj.value, //this is the input you would send 
        timeout: 90000, //your browser will give up after the given time(if your server cannot response in the setting time.)
        success: function(html){$('#DisplayName').val(html)});//this will tell what will be done in case of success, by success it mean that your php page responded, you can modify your response to failure even if you php page is found. that advance for you
        }
        </script>
        <input type=text onchange='GetName(this)'>
        <div id='DisplayName'></DIV>
        please download and link jQuery.js file. You are a beginner it might be confusing to you...........

        Comment

        Working...