admin管理员组文章数量:1398782
I have a simple checkbox on my website. Everytime you check and uncheck it, it shows an alert as to what the state is. This works flawlessly in FF, Chrome, and IE8. However, when I run this in IE7, no matter if the check is on or off, it always alerts "off". It's like IE7 can't detect that the checkbox is checked.
Does anyone have an idea of how to fix this or work around it? I basically need to toggle the visibility of some content based on a checkbox, but IE7 is being difficult. Thanks!
Here is my code that I'm using:
function showHideTimeDropdown()
{
if (document.getElementById("input_checkbox").checked == true){
alert("on");
}
else{
alert("off");
}
}
EDIT:
Okay, turns out that having the Name and the ID of the element confused the browser. I made the name of the element different than the ID and that solved it.
Thank you both for helping me out. Just hearing that you guys had tried it and couldn't replicate my problem told me that perhaps I was looking in the wrong place, of which I was :)
I have a simple checkbox on my website. Everytime you check and uncheck it, it shows an alert as to what the state is. This works flawlessly in FF, Chrome, and IE8. However, when I run this in IE7, no matter if the check is on or off, it always alerts "off". It's like IE7 can't detect that the checkbox is checked.
Does anyone have an idea of how to fix this or work around it? I basically need to toggle the visibility of some content based on a checkbox, but IE7 is being difficult. Thanks!
Here is my code that I'm using:
function showHideTimeDropdown()
{
if (document.getElementById("input_checkbox").checked == true){
alert("on");
}
else{
alert("off");
}
}
EDIT:
Okay, turns out that having the Name and the ID of the element confused the browser. I made the name of the element different than the ID and that solved it.
Thank you both for helping me out. Just hearing that you guys had tried it and couldn't replicate my problem told me that perhaps I was looking in the wrong place, of which I was :)
Share Improve this question edited May 5, 2010 at 6:04 justinl asked May 5, 2010 at 4:18 justinljustinl 10.6k22 gold badges71 silver badges90 bronze badges3 Answers
Reset to default 4Okay, turns out that having both the Name and the ID of the element the same confused the browser. I made the name of the element different than the ID and that solved it.
Hi there i wanted to help but I was unable to duplicate the problem.. below is the code I tried.
<html>
<head>
<script language="javascript">
function showHideTimeDropdown()
{
if (document.getElementById("input_checkbox").checked == true){
alert("on");
}
else{
alert("off");
}
}
window.onload = function () {showHideTimeDropdown();};
</script>
</head>
<body>
<input id="input_checkbox" type="checkbox" value="true" onchange="showHideTimeDropdown();">
<input type=text>
</body>
</html>
This code works in IE7. Perhaps you can post the code for the checkbox and for whatever event handler calls the "showHideTimeDropdown" function.
<html>
<head>
<script>
function showHideTimeDropdown()
{
if (document.getElementById("input_checkbox").checked)
alert("on");
else
alert("off");
}
</script>
</head>
<body>
<input onclick="showHideTimeDropdown();" id="input_checkbox" type="checkbox"/>
</body>
</html>
本文标签: internet explorer 7How to detect checkbox state in Javascript IE7Stack Overflow
版权声明:本文标题:internet explorer 7 - How to detect checkbox state in Javascript IE7 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744613746a2615810.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论