admin管理员组文章数量:1389822
I'm trying to resolve whether or not a checkbox is checked. It seems rather straight forward.
<script type="text/Javascript">
function ValidateReqNum() {
var zCheckBox = document.getElementById('chkAllJobs');
if (zCheckBox.checked)
alert("true");
if (!zCheckBox.checked)
alert("false");
return true;
}
</script>
and the checkbox:
<asp:CheckBox ID="chkAllJobs" runat="server" Text="All Jobs" />
called from:
<asp:Button ID="btnPrintReport" runat="server" Text="Run Report"
OnClientClick="return ValidateReqNum();" OnClick="CreatePDFJobReport" />
I've tried it dozens of different ways and it keeps ing back with
Error: Unable to get value of the property 'checked': object is null or undefined
My other elements in the same aspx page are reporting in just fine. I can call chkAllJobs from my c# code and I can resolve whether or not it's checked from c# as well.
I'm trying to resolve whether or not a checkbox is checked. It seems rather straight forward.
<script type="text/Javascript">
function ValidateReqNum() {
var zCheckBox = document.getElementById('chkAllJobs');
if (zCheckBox.checked)
alert("true");
if (!zCheckBox.checked)
alert("false");
return true;
}
</script>
and the checkbox:
<asp:CheckBox ID="chkAllJobs" runat="server" Text="All Jobs" />
called from:
<asp:Button ID="btnPrintReport" runat="server" Text="Run Report"
OnClientClick="return ValidateReqNum();" OnClick="CreatePDFJobReport" />
I've tried it dozens of different ways and it keeps ing back with
Error: Unable to get value of the property 'checked': object is null or undefined
My other elements in the same aspx page are reporting in just fine. I can call chkAllJobs from my c# code and I can resolve whether or not it's checked from c# as well.
Share Improve this question edited Jan 4, 2013 at 0:23 Kaf 33.8k7 gold badges60 silver badges80 bronze badges asked Jan 3, 2013 at 23:35 user1947046user1947046 431 silver badge3 bronze badges 1- 1 your error message is telling you that zCheckBox is undefined, look at @Kaf's answer, that should go the trick – roman m Commented Jan 4, 2013 at 0:30
2 Answers
Reset to default 3If you are using master pages, control ids of child page at client will be different to their server ids. So instead of using server control name, try using its client id as;
var zCheckBox = document.getElementById('<%= chkAllJobs.ClientID %>');
function ValidateReqNum() {
alert(zCheckBox.checked);
}
Here is a sample how check-box work. If you have the following check-box:
<input id="Checkbox" type="checkbox" name="mycheckbox" value="5"/>
Then you can get the value using forms collection
label_Result.text = Request.Form["mycheckbox"];
Consequently, you will get the value 5 only if that checkbox is checked.
本文标签:
版权声明:本文标题:javascript - Checkbox "Error: Unable to get value of the property 'checked': object is null or undefine 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744673823a2618989.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论