简体   繁体   English

Javascript / jQuery隐藏基于选定下拉项的字段

[英]Javascript / jQuery Hide fields based on Selected Drop Down item

I have some code that I have created for an OnChange event which works perfectly. 我有一些为OnChange事件创建的代码,它可以正常工作。

<script type="text/javascript">
                    function UpdEventChanged(selectEl) {
                        var text = selectEl.options[selectEl.selectedIndex].text;
                        if (text == "Sickness" || text == "Holiday") {
                            $("input[id$=eventPostCode").hide();
                            $("#ContentPlaceHolder1_LBLUpdPCReq").hide();
                            $("#ContentPlaceHolder1_lblUpdPC").hide();
                        }

                        else {
                            $("input[id$=eventPostCode").show();
                            $("#ContentPlaceHolder1_LBLUpdPCReq").show();
                            $("#ContentPlaceHolder1_lblUpdPC").show();
                        }
                    }
</script>

I need to integrate the above code to make it work on the Page Load event. 我需要集成以上代码以使其在Page Load事件上正常工作。 Here is my code: 这是我的代码:

// update Dialog
    $('#updatedialog').dialog({
        autoOpen: false,
        width: 500,
        buttons: {
            "update": function() {
                //alert(currentUpdateEvent.title);

                var eventToUpdate = {
                    id: currentUpdateEvent.id,
                    //title: $("#eventName").val(),
                    title: $("#EventSalesPerson option:selected").text(),
                    description: $("#eventDesc").val(),
                    salesperson: $("#EventSalesPerson option:selected").text(),
                    eventPostCode: $("input[id$=eventPostCode]").val(),
                    eventname: $("#EventEventName option:selected").text()
                };

                 {
                    PageMethods.UpdateEvent(eventToUpdate, updateSuccess);
                    $(this).dialog("close");

                    currentUpdateEvent.title = $("#eventName").val();
                    currentUpdateEvent.description = $("#eventDesc").val();
                    currentUpdateEvent.salesperson = $("#EventSalesPerson option:selected").text();
                    currentUpdateEvent.eventname = $("#EventEventName option:selected").text();
                    currentUpdateEvent.eventPostCode = $("input[id$=eventPostCode]").val();

                    $('#calendar').fullCalendar('updateEvent', currentUpdateEvent);
                    location.reload(true);
                }

            },
            "delete": function() {

                if (confirm("do you really want to delete this event?")) {

                    PageMethods.deleteEvent($("#eventId").val(), deleteSuccess);
                    $(this).dialog("close");
                    $('#calendar').fullCalendar('removeEvents', $("#eventId").val());
                }

            }

        }
    });

If #EventEventName selected text = Holiday or Sickness then I need the following items to be hidden: 如果#EventEventName选择的文本=假日或疾病,那么我需要隐藏以下项目:

"input[id$=eventPostCode"
"#ContentPlaceHolder1_LBLUpdPCReq"
"#ContentPlaceHolder1_lblUpdPC"

And obviously if they are not selected then the above should be displayed. 显然,如果未选择它们,则应显示以上内容。

Thanks 谢谢

It looks like you need something about like this: 看来您需要以下内容:

var EventEventNameText = $('#EventEventName').val();
if (EventEventNameText=='Holiday' || EventEventNameText=='Sickness') {
    $('#eventPostCode').hide();
    $('#ContentPlaceHolder1_LBLUpdPCReq').hide();
    $('#ContentPlaceHolder1_lblUpdPC').hide();
}

Let me know how that works for you. 让我知道这对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据下拉菜单中选择的选项隐藏/显示文本字段? - How to hide/show text fields based on options selected in a drop down? 如何根据所选下拉列表的值按ID隐藏和显示div -JQuery和Javascript - How to hide and show div by ID based on the value of selected drop down -JQuery and Javascript jQuery根据选择下拉列表显示/隐藏多个“其他”输入字段 - jQuery show/hide multiple 'Other' input fields based on select drop down JavaScript / jQuery-侦听选定的下拉选项 - JavaScript / jQuery - Listening for selected drop down option 显示选定的下拉列表(javascript 或 jquery) - Display the selected of a Drop down list (javascript or jquery) 根据另一个下拉列表中的所选项目更改下拉所选项目 - Change drop down selected item based on selected item of another drop down list 如何使用 php ajax javascript 根据选定的下拉项更改表格的颜色 - how can I change the color of a table based on selected drop down item using php ajax javascript 使用没有 jQuery 的 JavaScript 从多个不同的选定下拉列表项中获取值 - Get values from multiple different selected drop down list item using JavaScript without jQuery 隐藏基于下拉菜单中所选选项的表单 - Hide a form based on the selected option in drop down menu 根据下拉菜单中的选择显示/隐藏表单字段 - Show/hide form fields based on a selection from a drop down menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM