I can not seem to get checkbox.checked to work, I have a script that changes an image based onclick() however i would like it to change it based on whether a checkbox is checked or not. what am i doing wrong? Also if someone may be able to adress this, the check boxes do not check in ie8
here is the live link: http://jsbin.com/uburan/1/edit
code:
<script type="text/javascript">
function func()
{
var img1= document.getElementById("img1");
if(checkbox.checked)
{
img1.src = "images/" + "img1a.jpg";
img1.name = "off";
}
else
{
img1.src = "images/" + "img1.jpg";
img1.name = "on";
}
}
</script>
</head>
<body>
<form>
<p align="center">
<input type="checkbox" name="interest1" id="interest1" value="x">
<input type="checkbox" name="interest2" id="interest2" value="x">
<input type="checkbox" name="interest3" id="interest3" value="x"></p>
<p align="center">
<label for="interest1" id="label-interest1"><img src="images/img1.jpg" width="781" height="800" onclick="func()" id="img1" /></label>
<label for="interest2" id="label-interest2"><img src="/images/img2.jpg" width="781" height="800" /></label>
<label for="interest3" id="label-interest3"><img src="/images/img3.jpg" width="781" height="800" /></label></P><!-- code making checkbox be an image-->
</form>
You have to specify the ID of the checkbox (or its reference inside the DOM). Something like this:
If you want to check if they’re all checked: