doukui2011 2013-06-04 11:27
浏览 19
已采纳

如何根据保管箱选择禁用特定输入文本?

<?php    
<SCRIPT LANGUAGE="JavaScript"><!--
    function codename() {
        if(document.Tipo.Tipo.value="1"){
            document.formname.nome.disabled="disable";
        }
        else {
            document.formname.nome.disabled="enable";
        }
    }
//-->
</SCRIPT>

<html>
<body>
    <form action ="registoDois.php" Method="post" align="center" name="formname">
    <table align="center">
            <td class="float-right">Tipo de conta:</label></td>
            <td>

            <select name="Tipo" id="Tipo">
                <option value="">Tipo:</option>
                <option value="1">Aluno</option>
                <option value="2">Professor</option>
                <option value="3">Admin</option>
            </select>


        <tr>
            <td class="float-right">Nome:</label></td>
            <td><input type="text" placeholder="Bruno" id="firstname" name="nome"  /></td>
        </tr>
    </table>
</form>
</html>
</body>

?>

I have a dropbox and an input text in a form that should disable according to the selection in the dropbox. For example if the user selects "Aluno" with the value "1" the javascript should disable the input text "name" from user input, but if the user selects another option from the dropbox the input text name is enabled.

  • 写回答

1条回答 默认 最新

  • dsy6639 2013-06-04 11:31
    关注

    Add an onchange to the select box..

    <select name="Tipo" id="Tipo" onchange="codename();">
        <option value="">Tipo:</option>
        <option value="1">Aluno</option>
        <option value="2">Professor</option>
        <option value="3">Admin</option>
    </select>
    

    And you are missing <label> tags, <tr> tags and more. You really need to make sure your html is valid before adding javascript and what not..

    Check this jsfiddle for a working version of your html and javascript: http://jsfiddle.net/dovereem/L7wsa/2/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊