Recently I had the need to handle the selected index changed event in an ASP.NET page. I did not want to post back to the server as I just wanted to hide/show an HTML element, so jQuery was the perfect fit.
Below is the code. Basically, within the jQuery document ready funciton, I wire a function to each dropdown list ('select') change event. You will probably want to refine this to a single id or class. Each time the dropdown selected index changes, I want to check the text value, and if it contains some text, either show or hide an HTML element. I also set a checkbox control to checked using the client id within a script tag.
<script type="text/javascript">
$(function() {
$('select').change(function(e) {
if (this[this.selectedIndex].text.indexOf("SomeText") > 0) { $('#emailActivity').fadeIn("slow");
// Ensure checkbox initially checked
$('#<%=cbSendEmail.ClientID %>').attr('checked', true);
}
else {$('#emailActivity').fadeOut();
}
});
});
</script>