简体   繁体   English

隐藏和显示文本框以及基于该下拉选择的下拉菜单?

[英]Hide and show textbox and dropdown based on that dropdown selection?

I have a dropdown,Based on that dropdown selection i want to show other dropdown. 我有一个下拉菜单,基于该下拉菜单,我想显示其他下拉菜单。 My jquery Fuction.Jquery function was working fine But page load it was showing all dropdown you can see that image. 我的jQuery Fuction.Jquery函数运行正常,但页面加载显示了所有下拉列表,您可以看到该图像。

enter code here<script type="text/javascript">

    $(document).ready(function ()
    {
         $('#<%=ddlColumnName1.ClientID %>').change(function () {

             //Get DropDownList selected value
             var selectedValue = $('#<%=ddlColumnName1.ClientID %>').val();
             debugger;
             //Enable Controls 
             if (selectedValue == 'Select Column') {
                 $('#<%=ddlContractArea.ClientID %>').hide();
                  $('#<%=ddlBusinessArea.ClientID %>').hide();
                 $('#<%=ddlContractingParty2.ClientID %>').hide();
                 $('#<%=ddlContractingParty3.ClientID %>').hide();
                 $('#<%=ddlContractingParty4.ClientID %>').hide();
              }
             if (selectedValue == 'ContractArea') {
                 $('#<%=ddlContractArea.ClientID %>').show();
                 $('#<%=ddlBusinessArea.ClientID %>').hide();
                 $('#<%=ddlContractingParty2.ClientID %>').hide();
                 $('#<%=ddlContractingParty3.ClientID %>').hide();
                 $('#<%=ddlContractingParty4.ClientID %>').hide();
             }

         });
     });


</script>

Mydropdown: Mydropdown:

<asp:DropDownList ID="ddlColumnName1" runat="server" CssClass="field_ddl_contractdetails"  >
                                                                </asp:DropDownList>

In my page load: if i give like this in page load all dropdown is not visible but after that if i select any value from first dropdown other dropdowns are not showing javascipt function is not working. 在我的页面加载中:如果我在页面加载中给出这样的内容,则所有下拉列表都不可见,但是在此之后,如果我从第一个下拉列表中选择了任何值,则其他下拉列表将不显示javascipt函数无法正常工作。

In page load only i want to show ddlColumnName1 dropdown.But it was showing all dropdown. 在页面加载中,我只想显示ddlColumnName1 dropdown.but它显示所有下拉列表。 Please some one tell how can i do this.In page load all dropdown are invisible based on that ddlColumnName1 selection i need to display other drop downs. 请告诉我该怎么做。在页面加载中,根据我需要显示其他下拉列表的ddlColumnName1选择,所有下拉列表都不可见。

Try hiding elements on page load in $(document).ready(function(){}); 尝试在页面加载时将元素隐藏在$(document).ready(function(){});

<script type="text/javascript">
  $(document).ready(function() {

    //hide elements on page load
    $('#<%=ddlContractArea.ClientID %>').hide();
    $('#<%=ddlBusinessArea.ClientID %>').hide();
    $('#<%=ddlContractingParty2.ClientID %>').hide();
    $('#<%=ddlContractingParty3.ClientID %>').hide();
    $('#<%=ddlContractingParty4.ClientID %>').hide();

    $('#<%=ddlColumnName1.ClientID %>').change(function() {

      //Get DropDownList selected value
      var selectedValue = $('#<%=ddlColumnName1.ClientID %>').val();
      debugger;
      //Enable Controls 
      if (selectedValue == 'Select Column') {
        $('#<%=ddlContractArea.ClientID %>').hide();
        $('#<%=ddlBusinessArea.ClientID %>').hide();
        $('#<%=ddlContractingParty2.ClientID %>').hide();
        $('#<%=ddlContractingParty3.ClientID %>').hide();
        $('#<%=ddlContractingParty4.ClientID %>').hide();
      }
      if (selectedValue == 'ContractArea') {
        $('#<%=ddlContractArea.ClientID %>').show();
        $('#<%=ddlBusinessArea.ClientID %>').hide();
        $('#<%=ddlContractingParty2.ClientID %>').hide();
        $('#<%=ddlContractingParty3.ClientID %>').hide();
        $('#<%=ddlContractingParty4.ClientID %>').hide();
      }

    });
  });
</script>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM