Forum Moderators: open
Anyway...
Fotiman very kindly posted some code to do this...
<script type="text/javascript">
function isChecked( checkboxId )
{
var cbox = document.getElementById(checkboxId);
if(!cbox ) return false;
if( cbox.checked )
{
return true;
}
return false;
}
</script>
<form onsubmit="return isChecked(myCheckBox)">
<input type="checkbox" id="myCheckBox" name="myCheckBox">
<input type="submit" name="submit" value="Submit">
</form>
But my knowledge of javascript is a bit basic, so how do I use the returned value of the function to create an alert?
Also, including the onsubmit part seems to stop my form from actually submitting?
<script type="text/javascript">
function isChecked( checkboxId )
{
var cbox = document.getElementById(checkboxId);
var valid = cbox.checked; /* boolean value */
if(!valid)
alert("Oi! That box ain't checked");
return valid;
}
</script>
<form onsubmit="return isChecked(myCheckBox)">
<input type="checkbox" id="myCheckBox" name="myCheckBox">
<input type="submit" name="submit" value="Submit">
</form>