0

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

3
Contributors
3
Replies
18
Views
3 Years
Discussion Span
Last Post by nurul_1
0

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>
0

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);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.