How to determine the state of a checkbox in Javascript IE7

I have a simple checkbox on my website. Every time you check and uncheck the box, it shows a status warning. 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 warns of disconnection. How IE7 can't detect the checkbox is checked.

Does anyone have any idea 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 tricky. Thanks!

Here is my code that I am using:

function showHideTimeDropdown()  
{   
  if (document.getElementById("input_checkbox").checked == true){
    alert("on");
  }
  else{  
    alert("off");  
  }  
}

      

EDIT:
Ok, it turns out that the name and ID of the item are confusing the browser. I made an item name other than ID and solved it.

Thanks for helping me. Just hearing that you guys tried and couldn't reproduce my problem, told me that maybe I was looking in the wrong place I was in :)

+2


a source to share


3 answers


Ok, so it turns out that having a Name and an Element ID is equally confusing to the browser. I made an item name other than ID and solved it.



+4


a source


Hi I wanted to help, but I was unable to reproduce the problem. Below is the code I have 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>

      

+1


a source


This code works in IE7. Perhaps you can post the code for the checkbox and for any 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>

      

+1


a source







All Articles