Hi,please help me.
I have a textbox called txtUsername, also have one called txtEmpID. what im looking for is a simple way for txtempid can get updated automattically based one what i type in txtusername.
Thank you

Recommended Answers

All 3 Replies

So, doing this client side would be best so you dont have to use PHP on each postback to check/assign the values..

If you want simple, use jQuery...

here is an example of one way to do this...

<!DOCTYPE html>
<html>
<head>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">
 </script>

</head>
<body>
UserName: <input id="txtUsername" type="text" /><br/>
EmpID: <input id="txtEmpID" type="text" />

<script>
$('#txtUsername').keypress(function(){
   $('#txtEmpID').val($('#txtUsername').val())
});

</script>
</body>
</html>

jquery or javascript is a powerful tool to do that thing :)

Thank you for your response and answer.I appreciate it and I will try it.

For my code now, the ID appear when I typed the name,but I want the ID appear in textbox. Please help me.Here are my codes.

This is getuserform.php

  <html>
    <head>
    <script>
    function showUser(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      } 
    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)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getuser2.php?q="+str,true);
    xmlhttp.send();
    }
    </script>
    </head>
    <body>

    <form>
      <p>
        <input type = "text" name="name" id="name" size ="35" onChange="showUser(this.value,name.value)">
      </p>

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

    </body>
    </html>

This is getuser2.php

<?php


include("dbase.php");

 $q = $_GET['q']; 
 $query = "SELECT ID FROM student WHERE name = '".$q."'";

$result = mysql_query($query,$conn);



while($row = mysql_fetch_array($result)){

  echo "<tr>";

  echo "<td>" . $row['ID'] . "</td>";

  echo "</tr>";
  }



mysql_close($conn);
?>
Be a part of the DaniWeb community

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