Populate Text Field with PHP variable
<p>I'm retaining values in form elements after a form submit.  I've got it to work fine with a select box using the following:</p>

<pre><code>&lt;select name="BranchManager" class="formfield" id="BranchManager"onchange="document.forms[0].submit();SEinit();"&gt;&lt;option value=""&gt;-- Select Manager --&lt;/option&gt;
         &lt;?php
            $area = $_POST['Area'];
            if ($area); {

               $BMquery = "SELECT DISTINCT Branch_Manager FROM Sales_Execs WHERE AREA = '$area' ".
               "ORDER BY Branch_Manager";

               $BMresult = mysql_query($BMquery);

               while($row = mysql_fetch_array($BMresult))
               {
                  echo "&lt;option value=\"".$row['Branch_Manager']."\"&gt;".$row['Branch_Manager']."&lt;/option&gt;\n  ";
               }
            }

        $branchmanager = $POST['BranchManager'];
        ?&gt;

       &lt;script type="text/javascript"&gt;
document.getElementById('BranchManager').value = &lt;?php echo json_encode(trim($_POST['BranchManager']));?&gt;;
&lt;/script&gt;
</code></pre>

<p>Which works fine (apologies if it isn't the cleanest/most efficient code, I'm doing my best!)  The next field is a text field that needs to be populated based off the Branch Managers name above.  So I've used :</p>

<pre><code>&lt;input name="BranchNum" type="text" class="formfield" id="BranchNum" size="3" maxlength="3" /&gt;
                      &lt;?php

                $bm = $_POST['BranchManager'];

                if ($bm); {

                $BNumquery = "SELECT DISTINCT BRANCH_NUM FROM Sales_Execs WHERE Branch_Manager = '$bm' ";

                $BNumresult = mysql_query($BNumquery);

                }

            $branchnum = $POST['BranchNum'];
            ?&gt;

   &lt;script type="text/javascript"&gt;
document.getElementById('BranchNum').value = &lt;?php echo json_encode($BNumresult);?&gt;;
&lt;/script&gt;
</code></pre>

<p>Which isn't working... where am I going wrong here?</p>
