I have an asp:CheckBox
with the following tag:
<asp:CheckBox ID="cbTest1" runat="server" onchange="cbChange(this.id);"/>
cbChange
is a Javascript function in the <head>
that looks like this (it's simple for now):
<script type="text/javascript">
function cbChange(senderID) {
alert('|' + senderID + '|'); // '|' is to help see string length
return false;
}
</script>
Now, whenever I click on cbTest1
, I get the alert box with the following text:
||
In other words, it's an empty/null string. I should also note that when I use a more traditional <input>
that I get the expected results:
(Code for <input>
)
<input type="checkbox" name="cbtest2" id="cbtest2" onchange="cbChange(this.id);" />
(Text in alert box when I check cbtest2
)
|cbtest2|
Why would I be getting the null/empty string with the asp:Checkbox
, but expected behaviour with the <input>
?
EDIT I did a little bit more research, since the asp:CheckBox
has the ID
attribute instead of (lowercase) id
, so I tried onchange="cbChange(this.ID);"
. Now I get the following output in the alert box:
|undefined|
Why would this also be happening?