RadioButtonList change event in jquery


Trap RedioButtonList change event in Jqury OR RadioButtonList selected value in Jquery:

<asp:RadioButtonList ID="rblBannerType" ClientIDMode="Static" runat="server" 
              RepeatDirection="Horizontal" >
    <asp:ListItem Value="image" Selected="True">Image</asp:ListItem>
    <asp:ListItem Text="html" >Html</asp:ListItem>
</asp:RadioButtonList> 

//jquery script
<script>
	$(function () {
		var t = $("#rblBannerType input:checked").val();
		SetBannerType(t);

		//Banner Type
		$("#rblBannerType").change(function () {
			var type = $("#rblBannerType input:checked").val();
			SetBannerType(type);
		});
	});
	function SetBannerType(type) {
		if (type == "image") {
			$("#divImage").show();
			$("#divHtml").hide();
		}
		else {
			$("#divHtml").show();
			$("#divImage").hide();
		}
	}
</script>
Advertisements
Tagged with: ,
Posted in Asp.Net, C#
2 comments on “RadioButtonList change event in jquery
  1. Colin McBride says:

    Hi, this will work if you change

    //Banner Type
    $(“#rblBannerType”).change(function () {
    var type = $(“#rblBannerType input:checked”).val();
    SetBannerType(type);
    });

    to

    //Banner Type
    $(“#rblBannerType input”).change(function () {
    var type = $(“#rblBannerType input:checked”).val();
    SetBannerType(type);
    });

    Notice the extra input in the identifier.
    Thanks for the code though, works for me and I wasn’t aware of the clientidmode=static property.

  2. pahamad says:

    Thanks Colin 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Top Rated

Error: Please make sure the Twitter account is public.

Blog Stats
  • 30,188 hits
%d bloggers like this: