Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Estou criando um sistema de disparo de emails em ASP e preciso criar um botao de selecionar todos e de selecionar os check box do formulario peguei um exemplo num forum em html ele fucinona normal mas coloquei no meu ssitema no comeco nao funcionou corretamente pois so seleciona 2 check box quando tem 4 e quando tem 2 nao seleciona nenhum
abaixo o codigo do script em HTML :
<html>
<head>
<title>Formulário checkboxes</title>
<script type="text/JavaScript">
/*
*/
function mudaCor(id_da_linha){
if (document.f0 == null){ //esta linha eu não entendi, na sorte funcionou
if (document.f0.mestre.checked == 1) //verifica se o checkbox mestre foi prescionado,
document.getElementById(id_da_linha).style.background='#FFFFD4' //caso sim, é destacado todas ás àreas
else //selecionadas pelo checkbox mestre. Caso não o mesmo desmarca todos, tirendo o destaque colorido
document.getElementById(id_da_linha).style.background=''
}
else {//caso o usuário apenas marque um dos checkbox simples, o mesmo é destacado.
if (document.getElementById(id_da_linha).style.background != '' ){
if (document.f1.elements[id_da_linha].checked == 1)
document.getElementById(id_da_linha).style.background='#FFFFD4'
else
document.getElementById(id_da_linha).style.background=''
}
else
document.getElementById(id_da_linha).style.background='#FFFFD4'
}
}
function selecionar_tudo(){ //função que seleciona todos os checkbox atraves do checkbox mestre...
if (document.f1){
for (var i = 0; i < document.f1.elements.length; i++) {
if (document.f0.mestre.checked == 0) {
document.f1.elements[i].checked = 0
mudaCor(i)//tira o destaque de todos os checkbox caso o mestre seja desmarcado
}
else {
document.f1.elements[i].checked = 1
mudaCor(i)//marca todos os checkbos e destaca todos....
}
}
}
}
</script>
</head>
<body>
<form name="f0">
<input type="checkbox" name="mestre" onClick="java script:selecionar_tudo()"> Marcar/Desmarcar todos
</form>
<form name="f1">
<table name="table" width="100%">
<tr id=0>
<td><input type="checkbox" name="ch0" onClick="mudaCor('0')"> Opção 1 </td>
</tr>
<tr id=1>
<td><input type="checkbox" name="ch1" onClick="mudaCor('1')"> Opção 2 </td>
</tr>
<tr id=2>
<td><input type="checkbox" name="ch2" onClick="mudaCor('2')"> Opção 3 </td>
</tr>
<tr id=3>
<td><input type="checkbox" name="ch3" onClick="mudaCor('3')"> Opção 4 </td>
</tr>
<tr id=4>
<td><input type="checkbox" name="ch4" onClick="mudaCor('4')"> Opção 5 </td>
</tr>
</table>
</form>
</body>
</html>
AGORA O MEU CODIGO :
<%
On Error Resume Next
Dim conteudo
conteudo = Request.Form("conteudo")
Session("conteudo") = conteudo
if conteudo = "" then
conteudo = Session("conteudo")
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<title>System for Web Solutions</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css"> background-color: #005C99;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}.titulo { font-family: Verdana;
font-size: 10px;
color: #FFFFFF;
}</head>
<body>
<table width="875" border="0" align="center" cellpadding="0" cellspacing="0">
<!-- fwtable fwsrc="Contato Online.png" fwbase="conteudo.jpg" fwstyle="Dreamweaver" fwdocid = "1118439019" fwnested="0" -->
<tr>
<td><img src="images/spacer.gif" width="32" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="23" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="233" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="508" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="79" height="1" border="0" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="1" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r1_c1" src="images/conteudo_r1_c1.jpg" width="875" height="5" border="0" id="conteudo_r1_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="5" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r2_c1" src="images/conteudo_r2_c1.jpg" width="875" height="119" border="0" id="conteudo_r2_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="119" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r3_c1" src="images/conteudo_r3_c1.jpg" width="875" height="15" border="0" id="conteudo_r3_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="15" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5" bgcolor="#FFFFFF"> </td>
<td><img src="images/spacer.gif" width="1" height="28" border="0" alt="" /></td>
</tr>
<tr>
<td rowspan="3"><img name="conteudo_r5_c1" src="images/conteudo_r5_c1.jpg" width="32" height="50" border="0" id="conteudo_r5_c1" alt="" /></td>
<td colspan="2" bgcolor="#FFFFFF"> </td>
<td rowspan="3" colspan="2"><img name="conteudo_r5_c4" src="images/conteudo_r5_c4.jpg" width="587" height="50" border="0" id="conteudo_r5_c4" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="20" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="2"><img name="conteudo_r6_c2" src="images/conteudo_r6_c2.jpg" width="256" height="10" border="0" id="conteudo_r6_c2" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="10" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="2" bgcolor="#FFFFFF"> </td>
<td><img src="images/spacer.gif" width="1" height="20" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r8_c1" src="images/conteudo_r8_c1.jpg" width="875" height="31" border="0" id="conteudo_r8_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="31" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="2" background="images/conteudo_r9_c1.jpg"> </td>
<td colspan="2" bgcolor="#EFEEE9" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr></tr>
<tr>
<td></td>
</tr>
<tr></tr>
<tr>
<td><%
response.Write (Session("conteudo"))
response.Write ("</br>")
'response.Write (conteudo)
'response.End()
Dim Tipo_usuario, Idioma, nome, nascimento
Dim tipo_criterio, criterio
Tipo_usuario = Request.Form("Tipo_usuario")
Idioma = Request.Form("Idioma")
nome = Request.Form("nome")
nascimento = Request.Form("nascimento")
'response.write(Tipo_usuario)
'response.write("</br>")
'response.write(Idioma)
'response.write("</br>")
'response.write(nome)
'response.write("</br>")
'response.write(nascimento)
'response.write("</br>")
'response.end()
if Tipo_usuario <> "" then
tipo_criterio = "Tipo_usuario"
criterio = Tipo_usuario
end if
if Idioma <> "" then
tipo_criterio = "Idioma"
criterio = Idioma
end if
if nome <> "" then
tipo_criterio = "nome"
criterio = nome
end if
if nascimento <> "" then
tipo_criterio = "nascimento"
criterio = nascimento
end if
'Aqui vamos abrir a conexão para resgatar valores do banco de dados
strCon = "DBQ=d:\web\localuser\wizardpirituba\www\dados\emailmkt.mdb;Driver={Microsoft Access Driver (*.mdb)};"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.CursorLocation = 3
objRS.CursorType = 0
objRS.LockType = 1
'if tipo_criterio <> "" then
if tipo_criterio = tipo_criterio then
strSQL = "SELECT * FROM TB_USERS where Unidade ='Chacara Inglesa' AND " & tipo_criterio & "= '" & criterio & "'"
else
strSQL = "SELECT * FROM TB_USERS where Unidade ='Chacara Inglesa'"
end if
if tipo_criterio = "" then
strSQL = "SELECT * FROM TB_USERS where Unidade ='Chacara Inglesa'"
'response.end()
end if
objRS.Open strSQL, strCon
If not objRS.EOF then
On Error Resume Next
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr></tr>
<tr>
<td></td>
</tr>
<tr></tr>
<tr>
<td><p>
<%
'Aqui faremos o action apontando para a página de envio.
%>
<strong>Filtro de Selecão </strong></p>
<form id="filtro" name="filtro" method="post" action="selecionar_emails.asp">
<p><strong>Pesquisar Por </strong>: </p>
<table width="297" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="172"><strong>Tipo de
usuário</strong></td>
<td width="125"><select name="Tipo_usuario" id="Tipo_usuario">
<option value="">Selecione</option>
<option value="Aluno">Aluno</option>
<option value="Ex-aluno">Ex-aluno</option>
<option value="Outros">Outros</option>
</select></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td> </td>
</tr>
<tr>
<td><strong>Idioma Interessado </strong></td>
<td><select name="Idioma" id="Idioma">
<option value="">Selecione</option>
<option value="Ingles">Ingles</option>
<option value="Espanhol">Espanhol</option>
<option value="Frances">Frances</option>
<option value="Alemao">Alemao</option>
<option value="Italiano">Italiano</option>
<option value="Chines">Chines</option>
<option value="Japones">Japones</option>
<option value="Portugues">Portugues</option>
</select></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td> </td>
</tr>
<tr>
<td><strong>Nome</strong></td>
<td><input name="nome" type="text" id="nome" /></td>
</tr>
<tr>
<td><div align="center"></div></td>
<td> </td>
</tr>
<tr>
<td><strong>Data de Nascimento </strong></td>
<td><input name="nascimento" type="text" id="nascimento" /></td>
</tr>
</table>
<p>
<input type="hidden" name="conteudo" value='<%=conteudo%>' />
</p>
<p>
<input type="submit" name="Submit2" value="Pesquisar" />
</form>
<form name="f0" id="f0">
<input type="checkbox" name="mestre" onclick="java script:selecionar_tudo()" />
Marcar Todos / Desmarcar todos
</form>
<p> </p>
<form action="set.asp" method="post" name="f1" id="f1">
<p align="center">Assunto
<input name="assunto" type="text" id="assunto" />
</p>
<p align="center">Unidade
<select name="unidade" id="unidade">
<option value="atendimentopsd@wizardpirituba.com.br">Pq. São Domingos</option>
<option value="atendimento@wizardpirituba.com.br">Chacará Inglesa</option>
</select>
</p>
<p align="center">
<input name="Submit" type="submit" class="texto" value="Enviar" />
</p>
<p align="left"><strong>Selecione abaixo os destinatários :</strong></p>
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="20" height="20" align="center" bgcolor="#006699" ><span class="titulo">></span></td>
<td width="50%" height="20" bgcolor="#006699"><span class="style8">Nome</span></td>
<td width="50%" height="20" bgcolor="#006699"><span class="style8">E-mail</span></td>
</tr>
<% <tr id=<%=tr_id%>>
<td width="20" align="center"><p class="texto">
<% <input name="box" type="checkbox" onClick="mudaCor('<%=valor_cor%>')" value="<%= objRS("email")%>"/>
<% response.Write(tr_id)
response.Write("<br/>")
response.Write(valor_cor)
'response.Write("<br/>")
'response.Write(var_nameBox)
%>
</p>
</td>
<% <td width="50%" class="texto" ><%=objRS("nome")%></td>
<% <td width="50%" class="texto"><%=objRS("email")%></td>
</tr>
<% </table>
</form></td>
</tr>
</table>
<% </td>
</tr>
</table></td>
<td background="images/conteudo_r9_c5.jpg"> </td>
<td><img src="images/spacer.gif" width="1" height="217" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r10_c1" src="images/conteudo_r10_c1.jpg" width="875" height="14" border="0" id="conteudo_r10_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="14" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r11_c1" src="images/conteudo_r11_c1.jpg" width="875" height="123" border="0" id="conteudo_r11_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="123" border="0" alt="" /></td>
</tr>
<tr>
<td colspan="5"><img name="conteudo_r12_c1" src="images/conteudo_r12_c1.jpg" width="875" height="5" border="0" id="conteudo_r12_c1" alt="" /></td>
<td><img src="images/spacer.gif" width="1" height="5" border="0" alt="" /></td>
</tr>
</table>
</body>
</html>
<script type="text/JavaScript">
function mudaCor(id_da_linha){
if (document.f0 == null){ //esta linha eu não entendi, na sorte funcionou
if (document.f0.mestre.checked == 1) //verifica se o checkbox mestre foi prescionado,
document.getElementById(id_da_linha).style.background='#FFFFD4' //caso sim, é destacado todas ás àreas
else //selecionadas pelo checkbox mestre. Caso não o mesmo desmarca todos, tirendo o destaque colorido
document.getElementById(id_da_linha).style.background=''
}
else {//caso o usuário apenas marque um dos checkbox simples, o mesmo é destacado.
if (document.getElementById(id_da_linha).style.background != '' ){
if (document.f1.elements[id_da_linha].checked == 1)
document.getElementById(id_da_linha).style.background='#FFFFD4'
else
document.getElementById(id_da_linha).style.background=''
}
else
document.getElementById(id_da_linha).style.background='#FFFFD4'
}
}
function selecionar_tudo(){ //função que seleciona todos os checkbox atraves do checkbox mestre...
if (document.f1){
for (var i = 0; i < document.f1.elements.length; i++) {
if (document.f0.mestre.checked == 0) {
document.f1.elements[i].checked = 0
mudaCor(i)//tira o destaque de todos os checkbox caso o mestre seja desmarcado
}
else {
document.f1.elements[i].checked = 1
mudaCor(i)//marca todos os checkbos e destaca todos....
}
}
}
}
</script>Carregando comentários...