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/

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么