Showing posts with label DropDownList. Show all posts
Showing posts with label DropDownList. Show all posts

Friday, July 15, 2011

Using jQuery to change value of corresponsing drop down list

Scenario: I have two drop down lists and when I change the value of the first drop down, jQuery should change the value of the second drop down.

ASP.net and jQuery

<asp:DropDownList ID="TestTypeDropDown" runat="server"/>
<asp:DropDownList ID="TestTypeDropDown2" runat="server"/>

jQuery

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js%22%3E%3C/script>
<script type="text/javascript">
$(document).ready(function () {
            $("#<%=TestTypeDropDown.ClientID%>").bind('change', function () {
                $("#<%=TestTypeDropDown2.ClientID%>").val($("#<%=TestTypeDropDown.ClientID%>").val());
            });
</script>