I am trying to pass some data from the database to a few textboxes and textarea but i am currently stuck. I would really appreciate some help to solve this issue. this is the code i am working with. I am able to pass it to the table but not the textboxes.

function showUser(str) {
  if (str=="") {
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {



 $dropdown = "<select  name='custid'  onchange='showUser(this.value)'>";

 while ($row = mysqli_fetch_assoc($result2))
 { $dropdown .= "\r\n<option value='{$row['custid']}'>{$row['custid']}</option>";
 $dropdown .= "\r\n</select>";

 <p><label class="label" for="custid">Customer ID:</label><?php echo $dropdown; ?> <span class="ferror">* </span></p>

<div id="txtHint"><b>Person info will be listed here.</b></div>

<p><label class="label" for="model">Model:</label><input id="model" type="text" name="model" size="20" maxlength="20"  > </p>
<p><label class="label" for="imei">IMEI:</label><input id="imei" type="text" name="imei" size="20" maxlength="16" > </p>

<p><label class="label" for="issues">Issues:</label><textarea cols="40" rows="3" wrap="virtual" maxlength="100" id="issues" name="issues" > </textarea></span>
<p><label class="label" for="workdesc">Work Description:</label><textarea cols="40" rows="3" wrap="virtual" maxlength="100" id="workdesc" name="workdesc" > </textarea></span></p> 


PHP code

$q = intval($_GET['q']);


$sql="SELECT * FROM customer WHERE custid = '".$q."'";
$result = mysqli_query($dbcon,$sql);

echo "<table border='1'>

while($row = mysqli_fetch_array($result)) {
  echo "<tr>";
  echo "<td>" . $row['custName'] . "</td>";
  echo "<td>" . $row['equipment'] . "</td>";
  echo "<td>" . $row['manufacturer'] . "</td>";
  echo "<td>" . $row['model'] . "</td>";
  echo "<td>" . $row['imei'] . "</td>";
  echo "</tr>";

echo "</table>";


Thanks for any assistance its a major class project i need to get sorted.

Recommended Answers

All 2 Replies

Member Avatar

So what you are saying is you have a dropdown (combobox) and depending on the user selection it will populate the text box from the database?

Yes that is what i would love to take effect. After selecting the customer id i would love for the information in the database to populate the textboxes. Any help will be grateful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.