
Create a set of checkboxes with the below text: Which company do you work in? Infosys TCS Wipro Microsoft Google None of these If ââ?¬Å?None of theseââ?¬Â? is selected with any other, show a error message ââ?¬Å?Invalid selectionââ?¬Â?.

JavaScript Check box Validation
<html>
<script>
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}
function validate(){
var array = new Array();
var total=""
for(var i=0; i < document.f.company.length; i++){
if(document.f.company[i].checked)
array[i]=document.f.company[i].value;
}
if(array.contains("None of these")&&array.length>1){
alert("Invalid Selection");
}
return false;
}
</script>
<form name="f">
Which company do you work in?<br>
<input type="checkbox" name="company" value="Infosys">Infosys<br>
<input type="checkbox" name="company" value="TCS">TCS<br>
<input type="checkbox" name="company" value="Wipro">Wipro<br>
<input type="checkbox" name="company" value="Microsoft">Microsoft<br>
<input type="checkbox" name="company" value="Google">Google<br>
<input type="checkbox" name="company" value="None of these">None of these<br>
<input type="button" value="Check" onclick="validate();">
</form>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.