CheckBox Dinamico com PHP + Mysql

898 views
Skip to first unread message

Jeferson Cunha

unread,
Feb 5, 2012, 2:05:34 PM2/5/12
to PHPRS
Olá,
Estou listando informações do banco de dados,
Coloquei um form na minha apresentação, no qual quero marcar
(selecionar) quais desejo mandar por post.
é uma especie de algum de imagens, que eu vou listar para o click
marcar as fotos que ele deseja.
Dai vou mandar por post e enviar via mail() mesmo.

A dúvida é como usar o ckeckbox dinamico?

Zenon DC

unread,
Feb 13, 2012, 9:44:33 AM2/13/12
to lista...@googlegroups.com
Eu tenho dessa forma, vai ter que implementar no teu.

Agora é entender e usar.

Mastigado hein ;)

Aproveita.

Qualquer dúvida...



+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

head

<script>

function inserirCliente(){
document.location.replace("pessoa_edt.php");
}

function editarCliente(){
document.FRMcadastroCliente.action = 'pessoa_edt.php';
document.FRMcadastroCliente.submit();
}

function excluirCliente(){
  document.FRMcadastroCliente.action = 'pessoa_del.php';
  document.FRMcadastroCliente.submit();
}

function habilitarBotao(num) {
  document.getElementById('FRMchkTodas').checked = false;
  var verif = 0;
  for (cont = 0; cont < iQtdCli; cont++) {
 if (document.getElementById('FRMchkCliente_'+cont).checked == true) {
 verif++;
    }
}

if (verif == 0) {
document.getElementById('FRMbotaoExcluir').disabled = "disabled";
document.getElementById('FRMbotaoEditar').disabled = "disabled";
    document.getElementById('voto').style.display = 'none';
    //$("#score").removeAttr("value");
  } else if (verif == 1) {
document.getElementById('FRMbotaoExcluir').disabled = "";
document.getElementById('FRMbotaoEditar').disabled = "";
    document.getElementById('voto').style.display = '';
  } else if (verif > 1) {
document.getElementById('FRMbotaoExcluir').disabled = "";
document.getElementById('FRMbotaoEditar').disabled = "disabled";
    document.getElementById('voto').style.display = 'none';
}
}

function selecionaTodos(num) {
if (document.getElementById('FRMchkTodas').checked == true){
for (i = 0; i < iQtdCli; i++) {
document.getElementById('FRMchkCliente_'+i).checked = true;
document.getElementById('FRMbotaoExcluir').disabled = "";
  }
} else {
for (i = 0; i < iQtdCli; i++) {
document.getElementById('FRMchkCliente_'+i).checked = false;
document.getElementById('FRMbotaoExcluir').disabled = "disabled";
}
}
}



</script>

<body>

 <table width="100%" height="400" border="0" class="border">
<tr>
 <td width="160" valign="top" align="center">
 <form name="FRMcadastroCliente" id="FRMcadastroCliente" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" >
 <?php
$sStyle = 'text-decoration: none; color: teal;';
 ?>
 <table border="0" width="99%">
<tr>
 <td align="center">
 <input type="button" name="retornar" value="Voltar" onClick="document.location.replace('menu.php');">
 <input type='button' name='FRMbotaoExcluir' id='FRMbotaoExcluir' onclick='excluirCliente()' disabled='disabled' value='Excluir Usuário' />
 <input type='button' name='FRMbotaoEditar'  id='FRMbotaoEditar'  onclick='editarCliente()'  disabled='disabled' value='Editar Usuário' />
 <input type='button' name='FRMbotaoInserir' id='FRMbotaoInserir' onclick='inserirCliente()' value='Incluir Usuário' />
 </td>
</tr>
<tr>
 <td align="center">
<table width="99%" cellpadding="0" cellspacing="0" border="0" style="background-color: #FFF" class="table" >
 <tr align="left">
<td nowrap="nowrap" width="20%">
  <input type="checkBox" name='FRMchkTodas' id='FRMchkTodas' onclick='selecionaTodos()'>

  <b>coluna 1</b>
</td>
<td> coluna 2 </td>
<td> coluna 3 </td>
 </tr>
 <?php
 for ($i = 0; $i < $oBj ->iLinhas; $i++) {
 //verifica linha para colocar cor zebrado
 ?>
 <tr <?php echo ($i % 2 == 0 ? 'bgcolor="#E8E8E8"' : '') ?>  align="left">
 <label for="FRMchkCliente_<?php echo $i; ?>">
<td>
 <input type='checkbox' name='FRMchkCliente[]' id='FRMchkCliente_<?php echo $i; ?>' value='<?php echo $oBj->ID[$i] ?>' onclick='habilitarBotao(<?php echo $i; ?>)' />
 <?php
echo $oBj ->coluna1[$i];
 ?>
</td>
<td align="center">
 <?php
echo $oBj ->coluna2[$i];
 ?>
</td>
<td align="center">
 <?php
  echo $oBj ->coluna3[$i];
 ?>
</td>
 </label>
 </tr>
 <?php
 }
 ?>
<script>
var iQtdCli = <?php echo $oBj->iLinhas; ?>;
function selecionaTodos () {
if (document.getElementById('FRMchkTodas').checked == true){
for (i = 0; i < iQtdCli; i++) {
 document.getElementById('FRMchkCliente_'+i).checked = true;
 document.getElementById('FRMbotaoExcluir').disabled = "";
  if (iQtdCli == 1) {
document.getElementById('FRMbotaoEditar').disabled = "";
  }
}
} else {
for (i = 0; i < iQtdCli; i++) {
 document.getElementById('FRMchkCliente_'+i).checked = false;
 document.getElementById('FRMbotaoExcluir').disabled = "disabled";
 if (iQtdCli == 1) {
document.getElementById('FRMbotaoEditar').disabled = "disabled";
 }
}
 }
}
</script>
</table>
 </td>
</tr>
 </table>
</form>
</td>
</tr>
</table>
</body>
</html>





+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++









Att,

Zenon Dias.
Desenvolvimento de Sistemas WEB.


> Date: Sun, 5 Feb 2012 11:05:34 -0800
> Subject: [PHPRS] CheckBox Dinamico com PHP + Mysql
> From: gru...@jefersoncunha.com.br
> To: lista...@googlegroups.com
> --
> You received this message because you are subscribed to the Google
> Groups "PHPRS" group.
> To post to this group, send email to lista...@googlegroups.com
> To unsubscribe from this group, send email to
> lista-phprs...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/lista-phprs?hl=en

gabriel...@gmail.com

unread,
Feb 12, 2012, 9:10:09 PM2/12/12
to lista...@googlegroups.com
Jerferson, não entendi direito a sua dúvida, o que deve mudar, o que vai ser dinâmico no checkbox ??

Se você recarrega a página, quando muda as imagens, pode salvar o id na session, para depois  colocar em um campo escondido.

Se você faz isso por ajax, eu sugiro criar alguns campos escondidos e salvar os ids neles com Javascript.


Mas, ainda não tenho certeza se entendi sua pergunta.
------------------------------------------------------------------
Att. Gabriel Molter
http://twitter.com/gabriel_molter
gabriel dot molter at gmail dot com
GNU/Linux User #511488
-------------------------------------------------------------------



Rafael Jaques

unread,
Feb 17, 2012, 5:14:46 PM2/17/12
to lista...@googlegroups.com
Especifica melhor, por favor...

Um abraço,
:: Rafael Jaques
:: http://www.phpit.com.br - http://www.twitter.com/rafajaques
:: Cristão - Professor - PHP Developer - Gremista - Colunista MX Studio - Linux User: #422354
:: "Se confessarmos os nossos pecados, ele é fiel e justo para nos perdoar os pecados, e nos purificar de toda a injustiça." (1 João 1:9)


Em 5 de fevereiro de 2012 17:05, Jeferson Cunha <gru...@jefersoncunha.com.br> escreveu:
Reply all
Reply to author
Forward
0 new messages