How do I toggle show/hide of 2 controls based on value from ASP.NET DropDownList using jQuery?

I have an ASP.NET DropDownList

<asp:DropDownList ID="ddlIR" runat="server" Width ="204"></asp:DropDownList>

Open in new window


an ASP.NET label

<asp:Label ID="lblRR" runat="server" Text="Reject reason" Visible="False"></asp:Label>

Open in new window


and an ASP.NET TextBox control

<asp:TextBox ID="tbRR" runat="server" Width="200" Visible="False"></asp:TextBox>

Open in new window


The dropdownlist control is populated with three values
""
Accepted
Rejected

I want tbRR and lblRR to be visible when "Rejected" is selected from ddlIR
else
I want to hide tbRR and lblRR

How do I do this using jQuery?
Mike MillerSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
If Rejected value is Rejected

$(document).ready(function(){
    $('#ddlIR').on('change', function() {
      if ( this.value == 'Rejected')
      {
        $("#tbRR").show();
        $("#lblRR").show();
      }
      else
      {
         $("#tbRR").hide();
        $("#lblRR").hide();
      }
    });
});

Open in new window

Mike MillerSoftware EngineerAuthor Commented:
JavaScript runtime error: Object doesn't support property or method 'on'

I updated my jQuery library but nothing is happening. Here's my code...

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript">

    $(document).ready(function () {
        $('#ddlIR').on('change', function () {
            if (this.value == 'Rejected') {
                $("#tbRR").show();
                $("#lblRR").show();
            }
            else {
                $("#tbRR").hide();
                $("#lblRR").hide();
            }
        });
    });

	</script>

Open in new window


Note: all of this is just before the </head> tag
Najam UddinCommented:
try

$(document).ready(function(){
    $('#ddlIR').change(function() {
      if ( this.value == 'Rejected')
      {
        $("#tbRR").show();
        $("#lblRR").show();
      }
      else
      {
         $("#tbRR").hide();
        $("#lblRR").hide();
      }
    });
});

Open in new window


On fiddle https://jsfiddle.net/y7nytj9w/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike MillerSoftware EngineerAuthor Commented:
I think I got it. I was hiding the controls using visible="false"
Once I removed that, the code worked. I was able to hide them on laod by using:

    <script>
        $(function () {
            $("#tbRR").hide();
            $("#lblRR").hide();
        });
</script>

Open in new window


Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.