dongwupei7803 2012-08-02 16:44
浏览 32

使用PHP变量填充文本字段

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:

<select name="BranchManager" class="formfield" id="BranchManager"onchange="document.forms[0].submit();SEinit();"><option value="">-- Select Manager --</option>
         <?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 "<option value=\"".$row['Branch_Manager']."\">".$row['Branch_Manager']."</option>
  ";
               }
            }

        $branchmanager = $POST['BranchManager'];
        ?>

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

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 :

<input name="BranchNum" type="text" class="formfield" id="BranchNum" size="3" maxlength="3" />
                      <?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'];
            ?>

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

Which isn't working... where am I going wrong here?

  • 写回答

4条回答 默认 最新

  • dongshie8450 2012-08-02 16:46
    关注

    You need to put value="<? echo $variableName; ?>" inside the input field

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法