I have some ASP.Net code that defines a server-side checkbox like this:
<asp:CheckBox ID="_chkWindAndHail" runat="server" Text="Wind / Hail Deductible" TextAlign="Right" Checked="true" onClick="onControlChanged()" />
Then in the client-side event handler I have some Javascript that looks like this:
var chkWind = $("#<%= _chkWindAndHail.ClientID %>");
var hdnWind = $("#<%= _hdnWindAndHailPremium.ClientID %>");
var txtWind = $("#<%= _txtWindAndHailPremium.ClientID %>");
if (chkWind.checked)
txtWind.val(hdnWind.val);
else
txtWind.val(0);
When I try to look at the value of the “checked” property of the textbox, Firebug says the checkbox object is good but the “checked” property comes up “undefined” and thus in code it never sets a proper value.
Can someone explain to me what the heck I’m doing wrong? I’m new to JQuery, so this is probably something very basic.
Fastest way is to get the
checkedproperty, but you need to do it from the DOM element itself stored in the jQuery object.This retrieves the DOM element at index
0, and gives you thecheckedproperty. You were trying to get it from the jQuery object instead of the element.