W
W.Sh
Hello Everyone!
I'm having some issues with javascript that I can't seem to resolve...
Basically, I have a very simple code that's supposed to change the
innerHTML of a span element whenever I click on a checkbox. The
innerHTML reads "True" if the checkbox is checked, and "False" if the
checkbox is unchecked.
Now, the problem is that it only works when I check the checkbox, but
when I uncheck it nothing happens.
Here is a sample of the code I am using to do this:
....
<head>
<script type="text/javascript">
function CheckCheckbox(index)
{
if (document.getElementsByName("myCheck" + index).checked=true)
{
document.getElementById("mySpan" + index).innerHTML = "True"
}
else
{
document.getElementById("mySpan" + index).innerHTML = "False"
}
}
</script>
</head>
....
....
<body>
<input type="checkbox" name="myCheck0" onclick="CheckCheckbox(0)"
/><span id="mySpan0"></span>
<input type="checkbox" name="myCheck1" onclick="CheckCheckbox(1)"
/><span id="mySpan1"></span>
<input type="checkbox" name="myCheck2" onclick="CheckCheckbox(2)"
/><span id="mySpan2"></span>
</body>
....
As you can see, this is very basic and should work flawlessly, but for
some reason it only seems to work half way. When I click on a checkbox
to uncheck it, nothing is happening.
Does anyone have any ideas as to why this is happening ( or... not
happening )?
Any input will be very appreciated!
Thanks in advance!
W.Sh
I'm having some issues with javascript that I can't seem to resolve...
Basically, I have a very simple code that's supposed to change the
innerHTML of a span element whenever I click on a checkbox. The
innerHTML reads "True" if the checkbox is checked, and "False" if the
checkbox is unchecked.
Now, the problem is that it only works when I check the checkbox, but
when I uncheck it nothing happens.
Here is a sample of the code I am using to do this:
....
<head>
<script type="text/javascript">
function CheckCheckbox(index)
{
if (document.getElementsByName("myCheck" + index).checked=true)
{
document.getElementById("mySpan" + index).innerHTML = "True"
}
else
{
document.getElementById("mySpan" + index).innerHTML = "False"
}
}
</script>
</head>
....
....
<body>
<input type="checkbox" name="myCheck0" onclick="CheckCheckbox(0)"
/><span id="mySpan0"></span>
<input type="checkbox" name="myCheck1" onclick="CheckCheckbox(1)"
/><span id="mySpan1"></span>
<input type="checkbox" name="myCheck2" onclick="CheckCheckbox(2)"
/><span id="mySpan2"></span>
</body>
....
As you can see, this is very basic and should work flawlessly, but for
some reason it only seems to work half way. When I click on a checkbox
to uncheck it, nothing is happening.
Does anyone have any ideas as to why this is happening ( or... not
happening )?
Any input will be very appreciated!
Thanks in advance!
W.Sh