根据下拉选项禁用保存按钮 [英] Disable the save button based on dropdown choice

查看:96
本文介绍了根据下拉选项禁用保存按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想禁用保存"当下拉式选单等于当面"时,该按钮可用于表格并且其下方的学校地址"文本框为空.我正在寻找解决方案 仅JavaScript .谢谢.

I would like to disable the "Save" button for a form when a dropdown equals "In Person" and a School Address text box below it is empty. I'm looking for a solution in JavaScript only. Thanks.

迈克

SharePoint工程师-迈克

SharePoint Engineer - Mike

推荐答案

此处是我的示例代码供您参考.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        function DDLChange() {
            var e = document.getElementById("mySelect");
            var option = e.options[e.selectedIndex].value;
            var school = document.getElementById("txt_School");
            if (option == "In Person" && school.value == "") {
                document.getElementById("btnSave").disabled = true;
            } else {
                document.getElementById("btnSave").disabled = false;
            }
        }
    </script>
</head>
<body>
    <select onchange="DDLChange()" id="mySelect">
        <option>a</option>
        <option>In Person</option>
        <option>c</option>
    </select>
    <br />
    <input id="txt_School" type="text" />
    <br/>

    <input id="btnSave" type="button" value="button" />
</body>
</html>

如果如果找不到控件ID,则可以考虑使用jQuery,这样可以帮助您更轻松地获取控件.

您可以检查下面的jQuery选择器链接.

https://api.jquery.com/category/selectors/

https://api.jquery.com/category/selectors/

最佳问候

Lee


这篇关于根据下拉选项禁用保存按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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