无法获取在JavaScript中的HTML复选框值
我试图让它可以是用户输入或从数据库中检索ASP.NET复选框值。但每次它显示此错误消息
I'm trying to get ASP.NET checkbox value which can be user input or retrieved from database. But each time it's showing this error message
0x800a138f - JavaScript的运行时错误:无法获取属性值
未定义
或空
引用
0x800a138f - JavaScript runtime error: Unable to get property '
value
' ofundefined
ornull
reference
我的HTML code:
My HTML code:
<input type="checkbox" id="myCheck" data-member="IsSubGroupNecessary" data-label="" data-provider="checkbox" onchange="IsSubGroupNeeded();"/>
JavaScript的code:
JavaScript Code:
function IsSubGroupNeeded() {
var Subgrp = document.getElementById('<%=myCheck.ClientID%>').checked;
if (Subgrp == true) {
loadgrdSubgroupItem();
}
};
更新:
错误问题被解决。
但我想打电话给loadgrdSubgroupItem功能时复选框值为true无论是用户输入或从数据库中检索。怎么办呢?
Update: The error issue is solved. But I want to call loadgrdSubgroupItem function when checkbox value is true whether it is user input or retrieved from database. How to do it?
您呈现HTML有 myCheck
的ID,所以你应该能够:
Your rendered HTML has an id of myCheck
so you should be able to:
function IsSubGroupNeeded() {
var Subgrp = document.getElementById('myCheck').checked;
if (Subgrp == true) {
loadgrdSubgroupItem();
}
};
在不需要服务器侧呼叫
Without the need for the server side call.
(我假设你拥有的你的asp.net标记的ClientIDMode =静态)