如何打印上述文本框

时间:2017-03-29 11:53:18

标签: php html

要求用户输入他/她的姓名,默认情况下,下面的用户名应显示相同的名称。 我试过这段代码,但它并没有帮助我!

<tr>
        <td class="TrackMediumBlue" align="right" width="138">Manager  Name   :</td>
        <td width="13">&nbsp;</td>
        <td width="477">
        <input name="ManagerName" type="TEXT" id="ManagerName" size="40"  maxlength="100">                </td>
      </tr>
      <tr>
        <td class="TrackMediumBlue" align="right" width="138">UserName   :</td>
        <td width="13">&nbsp;</td>
        <td width="477">
        <input name="ManagerName" type="TEXT" value="<?php echo ManagerName ?>" size="40"  maxlength="100">                </td>
      </tr>

请帮帮我!

2 个答案:

答案 0 :(得分:2)

您必须使用javascript:

执行此操作
<tr>
    <td class="TrackMediumBlue" align="right" width="138">Manager Name:</td>
    <td width="13">&nbsp;</td>
    <td width="477">
        <input name="ManagerName" type="TEXT" id="ManagerName" size="40"  maxlength="100">
    </td>
</tr>
<tr>
    <td class="TrackMediumBlue" align="right" width="138">UserName:</td>
    <td width="13">&nbsp;</td>
    <td width="477">
        <input name="ManagerName" type="TEXT" id="ManagerName2" size="40"  maxlength="100">
    </td>
</tr>
<script type="text/javascript">
    document.getElementById('ManagerName').addEventListener('blur', function() {
        document.getElementById('ManagerName2').value = this.value;
    });
</script>

id属性添加到第二个输入。在上面的例子中,我使用ManagerName2

编辑:所有代码一起。

答案 1 :(得分:1)

<script>
document.getElementById('ManagerName').addEventListener('blur', function() {
    document.getElementById('ManagerName2').value = this.value;
});
</script>
<tr>
        <td class="TrackMediumBlue" align="right" width="138">Manager  Name   :</td>
        <td width="13">&nbsp;</td>
        <td width="477">
        <input name="ManagerName" type="TEXT" id="ManagerName" size="40"  maxlength="100">                </td>
      </tr>
      <tr>
        <td class="TrackMediumBlue" align="right" width="138">UserName   :</td>
        <td width="13">&nbsp;</td>
        <td width="477">
        <input name="ManagerName2" type="TEXT" value="" size="40"  maxlength="100">                </td>
      </tr>