I'm just trying to get this checkbox to alert a message after it is checked and after it is unchecked by running a function in Javascript. I can get it to display the "checked" message but can't get the "unchecked" alert to come up.
<input type="checkbox" id="chbx" onchange="foo()">
<script type="text/javascript">
var checkbox = document.getElementById("chbx");
function foo(){
if(checkbox.checked=true){
alert("Checked!");
}
else {
alert("UnChecked!");
}
};
</script>
==or===, as what you're doing is setting the value (true every time). The second form is best. (Nevermind, I see you edited out the incorrect syntax.)