Find us on Google+ Kill the code: text
Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Monday, 12 March 2012

Count the number of Checkboxes selected

Untitled Document
Subject one two three four five

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<script type="text/javascript">
var i=0;
function isset(id) {
var n=document.getElementById(id);
if(n.checked==true) {
i++;
}
else {
i--;
}
}
function validate() {
document.getElementById('lbl').innerHTML=i+" Checkbox Selected";
}
</script>


<table width="100%"><br />
<tr>
<td width="20%">Subject </td>
<td> <input type="checkbox" id="1" onclick="return isset(this.id)" />one
<input type="checkbox" id="2" onclick="return isset(this.id)" />two
<input type="checkbox" id="3" onclick="return isset(this.id)" />three
<input type="checkbox" id="4" onclick="return isset(this.id)" />four
<input type="checkbox" id="5" onclick="return isset(this.id)" />five
</td>
<td> <input type="button" onclick="return validate()" value="Check"/> </td>
<td> <label id="lbl"> </label> </td>
</tr>
</table>

</body>
</html>