Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

cristhianofonseca

[RESOLVIDO] Marcar vários CHECKBOX com 1 click

Recommended Posts

Um ex pra você...

 

<script>function marcaTodos(){	var total = document.form.check.length;	for(i = 0;i<total;i++){		document.form.check[i].checked = true;	}		}		</script><html><body><form name = "form"><input type = "checkBox" name = "check"><input type = "checkBox" name = "check"><input type = "checkBox" name = "check"><input type = "checkBox" name = "check"><input type = "checkBox" name = "check"><input type = "checkBox" name = "check"><input type = "button" name = "checa" value = "checa" onclick =marcaTodos(); ></form></body></html>

Ai no caso eles tem que ter o mesmo nome..beleza..Abraço!

Compartilhar este post


Link para o post
Compartilhar em outros sites

oh mais ou menos assim

 

function marcaTodosNomesDiferentes(){	var obj = document.getElementById("form").children;	var total = obj.length-1;	for(i = 0;i<total;i++){		obj.item(i).checked = true;			}}		</script><html><body ><form name = "form" id = "form"><input type = "checkBox" name = "check" ><input type = "checkBox" name = "check1" ><input type = "checkBox" name = "check2" ><input type = "checkBox" name = "check3" ><input type = "checkBox" name = "check4" ><input type = "checkBox" name = "check5" ><input type = "button" name = "checa" value = "checa" onclick = marcaTodosNomesDiferentes(); ></form></body></html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

um exemplo com checkbox e outro com select multiple:

 

nesse exemplo voce clica para selecionar e deselecionar

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Seleciona tudo</title>
<script>
function selecionar_todas(retorno) {
var frm = document.form1;
for(i = 0; i < frm.length; i++) {		
	if(frm.elements[i].type == "checkbox") {
		frm.elements[i].checked = retorno;
	}
 }
}

function seleciona_tudo(retorno){
var s = document.form2.select;	
for(var i = 0; i < s.options.length; i++) {		
	s.options[i].selected =	retorno ? 'selected' : false;		
}
}
</script>
</head>

<body>
<table width="594" height="204" border="1">
 <tr>
<td width="274"><form id="form1" name="form1" method="post" action="">
  <p>
	<input type="checkbox" name="checkbox" value="1" onclick="return selecionar_todas(this.checked);" />
	Seleciona Todas</p>
  <p>
	<input type="checkbox" name="checkbox2" value="1" />
	<br />
	<input type="checkbox" name="checkbox3" value="1" />
	<br />
	<input type="checkbox" name="checkbox4" value="1" />
	<br />
	<input type="checkbox" name="checkbox5" value="1" />
  </p>
</form>	</td>
<td width="304" valign="top"><form id="form2" name="form2" method="post" action="">
  <p>
	<input type="checkbox" name="checkbox6" value="checkbox" onclick="return seleciona_tudo(this.checked);" />
	Seleciona Todas</p>
  <p>
	<select name="select" size="5" multiple="multiple">
	  <option value="1">1</option>
	  <option value="2">2</option>
	  <option value="3">3</option>
	  <option value="4">4</option>
	  <option value="5">5</option>
	</select>
	<br />
  <br />
	<br />
  </p>
</form>	</td>
 </tr>
</table>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.