Ir para conteúdo

Arquivado

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

Morpheus#2005

Habilitando texts de acordo com checkbox

Recommended Posts

Galera boa noite!

 

$(document).ready(function () {
   $('.abc').attr('disabled', true);
   if (("#enable").attr("checked")){
   $("#qtd").css("display", "block");
}else{
   $("#qtd").css("display", "none");
}
   });

Eu tenho um form com esse estrutura :

<tr class="gradeX">      
			<input name="Contest" type="checkbox" id="Contest" value="C" />
			<td ><input id="qtd" type="text" name="qtd" value="<%=(Rs2.Fields.Item("Quantidade").Value)%>" class="abc" /></td>
			<td class="center"><%=(Rs2.Fields.Item("Valor").Value)%></td>
		</tr> 

 

 

Como eu faço para marcar o check e ele habilitar o text correspondente??

 

abraçosssssss

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom dia,

 

Pode ser feito assim:

 

Html

<input id="contest" type="checkbox" value="c" name="contest" />
<input id="qtd" type="text" value="2" name="qtd" class="abc" />

jQuery

$(function(){
    $('#qtd').prop('disabled', true);
    $('#contest').on('click', function() {
           var check = $(this).prop('checked');
           if(check == true) {
               $('#qtd').prop('disabled', false);
           }
           else {
               $('#qtd').prop('disabled', true);
           }
    })
})

Espero que ajude.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Oi Angelo, bom dia!

 

para um só funciona só que eu tenho varios checks e varios inputs...assim :

 

check1 - input1 = ao clicar no check1 desabilita input 1

check2 - input2 = ao clicar no check2 desabilita input 2

check3 - input4 = ao clicar no check3 desabilita input 3

 

 

Tem como??

 

Obrigado aeee

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tenta assim:

 

jQuery

$(function(){
    var form = $('input[type=text]');
    form.attr('disabled',true);
    $('input[type=checkbox]').on('click', function() {
        var check = $(this).prop('checked');
        var input = $(this).next('input');
        if(check == true) {
               $(input).prop('disabled', false);
           }
           else {
               $(input).prop('disabled', true);
           }
    })
})

Html

<form>
	<input type="checkbox" value="1" name="check1" />
	<input type="text" value="1" name="input1" />
	<br/>
    <input type="checkbox" value="2" name="check2" />
	<input type="text" value="2" name="input2" />
    <br/>
    <input type="checkbox" value="3" name="check3" />
	<input type="text" value="3" name="input4" />
    <br/>
    <input type="checkbox" value="4" name="check4" />
	<input type="text" value="4" name="input4" />
</form>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não...testei aqui mas nao rolou....vou continuar quebrando a cabeça aqui com esse código seu...mas estamos no caminho;;

 

Obrigado

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ele esta funcionando, mas quando eu coloco dentro de uma tr ele nao roda...

 

<div id="centro">
  <form method="post" action="">
  
  <form>
  	<input type="checkbox" value="1" name="check1" />
	<input type="text" value="1" name="input1" />
	<table width="200" border="1">
      <tr>
        <td><input type="checkbox" value="2" name="check2" /></td>
        <td><input type="text" value="2" name="input2" /></td>
      </tr>
    </table>
  </form>
  </form>
  <br />
  <br />
</div>

obrigado ae....

Compartilhar este post


Link para o post
Compartilhar em outros sites

Testei mais o script acima nao funciona....segue ae gaera...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Readonly Input Box</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
 
<body>
<h1>Readonly Input Box</h1>
<form>
	<input type="checkbox" value="1" name="check1" />
	<input type="text" value="1" name="input1" />
	<br/>
    <input type="checkbox" value="2" name="check2" />
	<input type="text" value="2" name="input2" />
    <br/>
    <input type="checkbox" value="3" name="check3" />
	<input type="text" value="3" name="input3" />
    <br/>
    <input type="checkbox" value="4" name="check4" />
	<input type="text" value="4" name="input4" />
</form>
 
<script type="text/javascript">
    $(document).ready(function(){
      $(function(){
    var form = $('input[type=text]');
    form.attr('disabled',true);
    $('input[type=checkbox]').on('click', function() {
        var check = $(this).prop('checked');
        var input = $(this).next('input');
        if(check == true) {
               $(input).prop('disabled', false);
           }
           else {
               $(input).prop('disabled', true);
           }
    })
})
    });
</script>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá,

 

Toca essa linha:

var input = $(this).next('input');

Por esta:

var input = $(this).parent().next().children();

Mas o mais importante é: você entendeu o que eu modifiquei?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sensacionalllllllllllllllllllllllllllllllllllllllllllllllllllll perfeitoooooooooooooo showwwwwwwwwwwwwwwwwwwww muitíssimo obrigado....

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.