从下拉菜单中选择选项启用/禁用文本框 [英] Enable/disable of textbox on option selected from drop down menu

查看:107
本文介绍了从下拉菜单中选择选项启用/禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的是,只有从下拉菜单中选择某个选项才能访问文本框,并且我有如下的html表单:

What I want is that the text box is only accessible if a certain option is picked from the drop down menu and I have an html form as below:

 <tr>
 <td>a.&nbsp;Did any  of your staff participate in training or orientation sessions related to any aspect of social performance management, during the reporting year? </td>
 <td >
 <p>
   <select name="mfi_4_a_i">
     <option>Yes</option>
     <option>No</option>
     <option>No, but planning in future</option>
   </select>
 </p>
 <p>if not,and not planning please explain why not </p>
 <input type="text" name="mfi_4_a_ii" id="sdd" />
 </tr>

现在,当用户选择否选项,但在将来计划时,必须启用文本框必须禁用该文本框。

Now when a user selects the option No, but planning in future then the text box must be enabled otherwise the textbox must be disabled.

我该如何完成这项工作?

How do I accomplish this?

推荐答案

<

<select id="mfi_4_a_i" name="mfi_4_a_i" onChange="changetextbox();">
    <option>Yes</option>
    <option>No</option>
    <option>No, but planning in future</option>
</select>

<input type="text" name="mfi_4_a_ii" id="sdd" />

<script type="text/javascript">
function changetextbox()
{
    if (document.getElementById("mfi_4_a_i").value === "noy") {
        document.getElementById("sdd").disable='true';
    } else {
        document.getElementById("sdd").disable='false';
    }
}
</script>

这篇关于从下拉菜单中选择选项启用/禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆