Asp: RadioButton and javascript $ find () function
<asp:RadioButton ID="myButton" Text="Option" GroupName="group" runat="server" /> Why, in this case, does the javascript function call $find('<%= myButton.ClientID %>') return null ? I need to detect / change value in javascript client. $find() should be a shortcut for Sys.Application.findComponent() .
UPDATE: No problem with identifier, I tried $ find () in the chrome console with a real rendered identifier and still get null. And I want to get an Ajax control, not a DOM element.
You need to set clientIdMode to static if you don't have multiple instances:
<asp:RadioButton ClientIDMode="static" ID="myButton" Text="Option" GroupName="group" runat="server" /> OR
You need to use ClientID to access your button. But the script should be on the same page.
var radioButton = $('#<%= myButton.ClientID %>'); You can directly evaluate an element by its identifier, and you need not use find , you just need the id selector, since id is unique to html elements.
$(function(){ var myButton = $('#<%= myButton.ClientID %>'); alert(myButton.id); //with javascript myButton = document.getElementById('#<%= myButton.ClientID %>'); });