since questions about checkboxes are frequently returning subjects, I've put together this overview.
Read-only checkbox:
Suppose you have a checkbox which is checked or unchecked depending on the output of a database,
and you want to show the result without allowing the client to change it.
This is how you can achieve that:
<input type="checkbox" name="chkBox" value="1" checked onClick="window.focus;return false">Confirm by e-mail
Check random amount of checkboxes
<html>
<head>
<title>Checkboxes</title>
<script language="JavaScript">
formname="formName"
function init() {
obj=document.forms[formname].elements;
maxNr = 0;
cnt = 1;
for (i=0;i<obj.length;i++) {
name = "chkBox" + cnt;
if (obj[ i ].type=="checkbox" && obj[ i ].name == name) {
maxNr++;
cnt++;
}
}
}
function checkStatus() {
nrChecked = 0;
cnt = 1;
for (i=0;i<obj.length;i++) {
name = "chkBox" + cnt;
if(obj[ i ].type=="checkbox" && obj[ i ].name == name){
stat = eval("document.formName."+name);
if (stat.checked) { nrChecked++ }
cnt++;
}
}
if (nrChecked != maxNr) {
alert("You haven't selected all choices!\nStill "+ (maxNr - nrChecked) +" checkboxes unchecked!");
return false
}
return true
}
</script>
</head>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.