2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Chokladkakan
0

Hello Muhammad shah,

I'm not sure I got you, but I think you asked for a button which would check or uncheck all checkboxes on a webpage? If so, I whipped something together:

<html>
<head>
	<script type="text/javascript">
		function checkall(){
			boxes = document.getElementsByTagName("input");
			max = boxes.length;
			i = 0;
			
			for(i=0;i<=max;i++){
				boxes[i].checked = true;
			}
		}
		
		function uncheckall(){
			boxes = document.getElementsByTagName("input");
			max = boxes.length;
			i = 0;
			
			for(i=0;i<=max;i++){
				boxes[i].checked = false;
			}
		}
	</script>
</head>
<body>
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	<input type="checkbox">
	
	<br>
	
	<button onclick="checkall()">Check all</button>
	<button onclick="uncheckall()">Uncheck all</button>
</body>
</html>

The two small functions there find all inputs which are able to be checked (checkboxes and radiobuttons, that is). In other words, it's a very brief and general example, as it doesn't limit itself in scope, but that could of course be resolved.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.