Ir para conteúdo
Fórum Script Brasil
  • 0

O Que Esta De Errado !


FabioNet

Pergunta

Olá Pessoal,

eu fiz essa função para que eu possa fazer aparecer um Div caso o usuário marque a checkbox...

como eu tenho varias checkbox e cada check vai ter o seu proprio Div para que eu possa mostrar alguns campos....só que eu preciso saber qual Div devo mostrar conforme o check selecionado ???

vejam meu código abaixo:

function ShowDiv()

{

marcado = false;

theForm = document.form1;

for ( i=0; i<theForm.length; i++ )

{

if ( theForm.type == "checkbox" )

{

if (theForm.checked == true)

{

marcado = true;

}

}

}

if (marcado)

{

[b]//aqui é o meu Div recebendo o value do checkbox....mas isso aqui não funcionou !!!! :(

document.getElementById("+ document.form1.IdAge_Del.value +").style.display = 'block';

}

else

{

document.getElementById("+ document.form1.IdAge_Del.value +").style.display = 'none';

}

}

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Apesar de você ter "floodado", vou tentar ajudar. :P

<!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>
<script type="text/javascript">
function ShowDiv(id)
{
marcado = false;
theForm = document.form1;

for (i=0; i < theForm.length; i++ )
{
  if (theForm[i].type == "checkbox" )
  {
    if (theForm[i].checked == true)
    {
      marcado = true;
    }
  }


  if (marcado)
  {
    document.getElementById("div"+ id).style.display = 'block';
  }
  else
  {
  document.getElementById("div"+ id).style.display = 'none';
  }
}
}
</script>
<style type="text/css">

</style>
<title>Teste</title>
</head>
<body>
<form name="form1" id="form1" action="">
<input type="checkbox" name="check1" id="check1" value="1" onclick="ShowDiv(this.value)" />
<br />
<input type="checkbox" name="check2" id="check2" value="2" onclick="ShowDiv(this.value)" />
<br />
</form>

<div id="div1" style="display:none">
DIV 01
</div>
<div id="div2" style="display:none">
DIV 02
</div>

</body>
</html>

Você deveria ter colocado a verificação do (marcado) dentro do laço.

OBS: Novamente, não crie tópicos repetidos. Seu outro tópico foi excluído.

[]'s

Link para o comentário
Compartilhar em outros sites

  • 0

Apesar de você ter "floodado", vou tentar ajudar. :P

<!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>
<script type="text/javascript">
function ShowDiv(id)
{
marcado = false;
theForm = document.form1;

for (i=0; i < theForm.length; i++ )
{
  if (theForm[i].type == "checkbox" )
  {
    if (theForm[i].checked == true)
    {
      marcado = true;
    }
  }


  if (marcado)
  {
    document.getElementById("div"+ id).style.display = 'block';
  }
  else
  {
  document.getElementById("div"+ id).style.display = 'none';
  }
}
}
</script>
<style type="text/css">

</style>
<title>Teste</title>
</head>
<body>
<form name="form1" id="form1" action="">
<input type="checkbox" name="check1" id="check1" value="1" onclick="ShowDiv(this.value)" />
<br />
<input type="checkbox" name="check2" id="check2" value="2" onclick="ShowDiv(this.value)" />
<br />
</form>

<div id="div1" style="display:none">
DIV 01
</div>
<div id="div2" style="display:none">
DIV 02
</div>

</body>
</html>

Você deveria ter colocado a verificação do (marcado) dentro do laço.

OBS: Novamente, não crie tópicos repetidos. Seu outro tópico foi excluído.

[]'s

obrigado pela ajuda....mas eu acabei resolvendo dessa maneira aqui:

function ShowDiv()

{

marcado = false;

theForm = document.form1;

for ( i=0; i<theForm.length; i++ )

{

if ( theForm.type == "checkbox" )

{

if (theForm.checked == true)

{

marcado = true;

document.getElementById(theForm.value).style.display = 'block';

}

else

{

document.getElementById(theForm.value).style.display = 'none';

}

}

}

}

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...