Click here to Skip to main content
15,897,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.. i got problems with document.getElementById("chkBox") is null.
here is my javascript :
C#
function Check()
        {
              if(document.getElementById("chkBox").checked=true)
              {
                  document.getElementById("NA").style.display = "none";

              }

else{}}

html code:
XML
<form name="check">
                        <input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>
                       
                     </form>
Posted

XML
<input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>

1. Your checkbox is a server control
2. You have not given any ID to your control and trying to access via getElementbyID

Based on your code, make the following change and it should work:
1. Remove runat="server"
2. Put ID="chkBox"
 
Share this answer
 
Comments
MissNano 28-Sep-10 1:22am    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
MissNano 28-Sep-10 1:26am    
its working thanks you Sandeep~ :)
Sandeep Mewara 28-Sep-10 1:45am    
Good to know!
hello,

I also noticed that you are using document.getElementById but there is no id attribute.

<input type="checkbox" id="chkBox" name="chkBox" onclick="Check()" runat="server"/>
 
Share this answer
 
Comments
MissNano 28-Sep-10 1:15am    
nope still return the same error
Javascript:

XML
<script>
function Check()
{
if(document.getElementById("chkBox").checked)
{
  document.getElementById("NA").style.display = "none";
}
else
{
  document.getElementById("NA").style.display = "block";
}
}
</script>


HTML

XML
<form name="check">
<input type="checkbox" name="chkBox" onclick="Check()" runat="server"/>Click
</form>
<div id="NA">This is test</div>


This works on my browser
 
Share this answer
 
Comments
MissNano 28-Sep-10 1:18am    
doesnt work in my browser.. im using Firefox..
if(document.getElementById("chkBox").checked=true)

should be

if(document.getElementById("chkBox").checked==true)
 
Share this answer
 
Comments
MissNano 27-Sep-10 23:57pm    
nope.. still return the same error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900