Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Created July 1, 2013 17:16
Show Gist options
  • Save wescleymatos/5902740 to your computer and use it in GitHub Desktop.
Save wescleymatos/5902740 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>DEMONSTRAÇÃO: Marcar todas as Check Boxes de uma lista</title>
</head>
<body>
<script>
function checkAll(o){
console.log(o);
var boxes = document.getElementsByTagName("input");
for (var x=0;x<boxes.length;x++){
var obj = boxes[x];
if (obj.type == "checkbox"){
if (obj.name!="chkAll") obj.checked = o.checked;
}
}
}
$('#mark-all').click(function () {
$('table').find('input[type=checkbox]').attr('checked', this.checked);
});
</script>
<form>
<table border="1" width="50%">
<tr style="background:#c0c0c0">
<td width="30"><input type="checkbox" name="chkAll" id="mark-all" onClick="checkAll(this)" /></td>
<td><b>Nome</b></td>
<td><b>Idade</b></td>
</tr>
<tr>
<td><input type="checkbox" name="itm1" /></td>
<td>Zé</td>
<td>45</td>
</tr>
<tr>
<td><input type="checkbox" name="itm2" /></td>
<td>Luiz</td>
<td>66</td>
</tr>
</table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment