By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

auto complete textbox value from input of another texbox

P: 8
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
Dec 2 '11 #1
Share this Question
Share on Google+
3 Replies


100+
P: 1,059
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
Dec 2 '11 #2

P: 8
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.
Dec 2 '11 #3

100+
P: 1,059
Expand|Select|Wrap|Line Numbers
  1.  
  2. <script>
  3.  
  4. function GetName(obj)
  5. {
  6. $.ajax({url: "getName.php", //the php file that will do the query and  give the name
  7. type: 'POST', //the method you would use, not a big deal in some case, can be a huge deal in some case.  
  8. dataType: 'html', 
  9. data: "Id="obj.value, //this is the input you would send 
  10. timeout: 90000, //your browser will give up after the given time(if your server cannot response in the setting time.)
  11. 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
  12. }
  13. </script>
  14. <input type=text onchange='GetName(this)'>
  15. <div id='DisplayName'></DIV>
  16.  
please download and link jQuery.js file. You are a beginner it might be confusing to you...........
Dec 2 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.