473,378 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

populating from database and autofill textboxes using ajax,php

0 down vote favorite


I am facing a small problem regarding this topic.I had write a code to autofill textboxes from database values when I type a id value in the previous textfield.i.e.if I type userid,the next textfields will autofill from database without refresh in ajax and php.my problem is that I cant find the error in my code.help me to find out.Here is my code:

a.html

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2.     <html xmlns="http://www.w3.org/1999/xhtml">
  3.       <head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5.      <title>Untitled Document</title>
  6.    <script type="text/javascript">
  7.  
  8.    var url = "getagentids.php?param=";
  9.  
  10.     function handleHttpResponse() {
  11.     if (http.readyState == 4) {
  12.      results = http.responseText.split(",");
  13.        document.getElementById('agfn').value = results[0];
  14.        document.getElementById('agsal').value = results[1];
  15.        document.getElementById('agtel').value = results[2];
  16.        document.getElementById('agid').value = results[3];
  17.      }
  18.     }
  19.  
  20.  
  21.     function getagentids() {
  22.     var idValue = document.getElementById("agid").value;
  23.     var myRandom=parseInt(Math.random()*99999999);  // cache buster
  24.     http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
  25.     http.onreadystatechange = handleHttpResponse;
  26.     http.send(null);
  27.     }
  28.  
  29.  
  30.     function getHTTPObject() {
  31.     var xmlhttp;
  32.     /*@cc_on
  33.      @if (@_jscript_version >= 5)
  34.       try {
  35.           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  36.           } catch (e) {
  37.           try {
  38.               xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  39.               } catch (E) {
  40.               xmlhttp = false;
  41.               }
  42.           } 
  43.      @else
  44.       xmlhttp = false;
  45.      @end @*/
  46.     if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  47.      try {
  48.        xmlhttp = new XMLHttpRequest();
  49.        } catch (e) {
  50.         xmlhttp = false;
  51.         }
  52.        }
  53.        return xmlhttp;
  54.       }
  55.  
  56.  
  57.   var http = getHTTPObject(); // We create the HTTP Object
  58.  
  59.  
  60.  </script>
  61.     </head>
  62.  
  63.      <body>
  64.     <form name="schform"> 
  65.       <table> 
  66.      <tr> 
  67.     <td>Contact ID:</td> 
  68.     <td><input id="agid" type="text" name="contactid" onKeyUp="getagentids();"></td> 
  69.    </tr><tr> 
  70.    <td>Tel Number:</td> <td><input id="agtel" type="text" name="contacttel"></td> 
  71.     </tr><tr>
  72.    <td>Name:</td> <td><input id="agfn" type="text" name="contactfullname"></td> 
  73.   </tr><tr>
  74.  <td>Salutation:</td> <td><input id="agsal" type="text" name="contactsalutation"></td> 
  75.  </tr> 
  76.  <tr>  <td><input type="reset" value="Clear"></td> 
  77. <td></td> 
  78.  </tr> 
  79. </table> 
  80.  </form>
  81.  </body>
  82.  </html>
  83.  
getagentids.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.         $link = mysql_connect('localhost', 'arbiocua_mita', 'asd123$'); 
  4.         if (!$link) 
  5.         {
  6.         die('Could not connect: ' . mysql_error());
  7.          }
  8.          mysql_select_db('arbiocua_monomita');
  9.  
  10.         //$param=intval($_GET['contactid']); 
  11.  
  12.           if(strlen($param)>0)
  13.           { 
  14.             $result = mysql_query("SELECT ContactFullName, ContactSalutation,   ContactTel FROM contact WHERE ContactID LIKE '$param%'"); 
  15.                 if(mysql_num_rows($result)==1) 
  16.                    { 
  17.               while($myrow = mysql_fetch_array($result))
  18.              { 
  19.            $agentname = $myrow["ContactFullName"]; 
  20.             $agenttel = $myrow["ContactTel"]; 
  21.            $agentsal = $myrow["ContactSalutation"]; 
  22.            $agentid = $myrow["ContactID"]; 
  23.            $textout = $agentname.",".$agentsal.",".$agenttel.",".$agentid; 
  24.            } } 
  25.            else { $textout=" , , ,".$param; 
  26.            } } 
  27.         echo $textout;
  28.  
  29.        ?>
  30.  
**database**:

table name 'contact'
ContactID ContactFullName ContactSalutation ContactTel
Feb 5 '13 #1
1 3722
Rabbit
12,516 Expert Mod 8TB
Just saying something doesn't work gives no helpful information. You need to describe what isn't working, what debugging steps you took, the results of those steps, and any error messages you received.
Feb 5 '13 #2

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

Similar topics

3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
4
by: muskan | last post by:
hello, I want to fetch all the records from database one by one when I click on next button I have written this code for fetching the records from database. But it shows only first record....
1
by: rocksoft | last post by:
Hi, i have devloping web application in Asp.net and c#, i have used ajax to achieve the auto complete text box, my company using visual studio 2003, ajax auto complete text box...
3
by: bss | last post by:
Dear All, I have developing a French website using PHP & Ajax. In that I tried to display some French texts from mysql database using Ajax. Form local I got the text from db with Correct...
13
by: Marvin Zhang | last post by:
Hi, I'm not familiar with web programming, but I have a problem here. I have a page. When a user click one button on it, I will use AJAX to request a PHP script which will do a bunch of tasks,...
8
by: Bhuwan Bhaskar | last post by:
Hi, Can we access database (SQL) using AJAX ? Thanks, Bhuwan
17
by: Shalini Bhalla | last post by:
i have 2 tables bank master and branch details having bankcode as a common feild . i have designed a form in which i am filtering branches according to a particular bank code using ajax ,...
0
by: AnaOlinto | last post by:
Hi, I'm new using AJAX and I'm developing a page where I need to populate a CheckBoxList based on what the user types (it's like an AutoSuggest). I don't know how to bind the checkboxlist from the...
1
by: burtonfigg | last post by:
I have an ecard site. Part of that site allows users to enter their own message which then appears within a flash SWF file. This is an example page: ...
3
by: techbytes | last post by:
Iam working in jsp and using ajax to insert data into the table. After inserting the values in the table ,the values remains in the textboxes. I want to refresh the form after ,i click the save...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.