Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
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
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
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>Não...testei aqui mas nao rolou....vou continuar quebrando a cabeça aqui com esse código seu...mas estamos no caminho;;
Obrigado
Bom dia,
O que não rolou? O que código que lhe passei está funcionando !
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....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>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?
Troquei a linha mas nao rolou...o parent faz pegar a proxima classe ?
Veja funcionando aqui normalmente - http://angelorubin.besaba.com/HabilitandoCheckbox/
Sensacionalllllllllllllllllllllllllllllllllllllllllllllllllllll perfeitoooooooooooooo showwwwwwwwwwwwwwwwwwwww muitíssimo obrigado....
Bom dia,
Pode ser feito assim:
Html
jQuery Espero que ajude.