Q:

How can I change the value of a textbox based on an array index from a mySQL Query result?

Basically I want to change the value of a input text box based onclick of the div I have in the echo in the PHP below to the value of the Serial Number or $stuff[7]. For each of the results. 
<form method='POST' action='move_audit.php'>
    <div>
        <label for='serial_no'>Serial Number * </label><br />
        <input type='text' name='serial_no' id='serial_no' value=""/>
        <br /><br />
        <input type='submit' class='submit' value='Exchange'/>
    </div>
</form>

<?php
   include('include/dbConnection.php');
   //SQL statement
   $query = "CALL compoutofdate();";
   $query1= "SELECT * FROM compaudit;";         
   //Execute prepared MySQL statement
   $results = mysqli_query($dbc,$query) or die('Error querying database');
   $results1 = mysqli_query($dbc,$query1) or die('Error querying database');
   while($stuff = mysqli_fetch_array($results1))
   {
       echo "<div id='procsults' onclick='ChangeText();'>
                 <b>Employee Number:</b> $stuff[1]<br />
                 <b>Employee Name:</b> $stuff[2] $stuff[3] <br />
                 <b>Department:</b> $stuff[4]<br />
                 <b>Device Grid Location:</b> $stuff[5]<br />
                 <b>Status:</b> $stuff[6]<br />
                 <b>Serial Number:</b> $stuff[7]<br />
                 <b>Model:</b> $stuff[8]<br />
                 <b>MAC Address:</b> $stuff[9]<br />
                 <b>Received Date:</b> $stuff[10]<br />
                 <b>Exchanged:</b> $stuff[11]<br />
             </div>
             <script>
            function ChangeText()
            {
                document.getElementById('serial_no').value =".$stuff[7].";
            }
             </script>";
   }

   //Close dbConnect
   mysqli_close($dbc);
?> 

A:

I would suggest taking the javascript function out of the while loop and placing it before. After that, you would change the function to take/accept a value:
function ChangeText(inputValue) { 
 document.getElementById('serial_no').value=inputValue; 
}

Finally inside the loop, change onclick="ChangeText();" to onclick="ChangeText('$stuff[7]');"

