Destildar casilla
Publicado por sandra (2 intervenciones) el 16/04/2007 19:52:40
Hola, hice esto con ajax. Cuando tildo una casilla de verificación, aparece un cartel en un input type text que dice: "Está tildada". Esto funciona bien, pero cuando la destildo, el texto sigue quedando, lo que quisiera es que cambie a "No está tildada".
Son dos archivos: test.php y muestra_texto.php
***************************
test.php
***************************
<html>
<head>
<script>
function verificar_navegador(){
var com = null;
try{
com = new ActiveXObject("Msxml2.XMLHTTP");//versión más nueva de internet explorer
}
catch(e){
try{
com = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2){
com=new XMLHttpRequest();//para los otros navegadores
}
}
return com;
}
function mostrar_texto(){
var com = verificar_navegador();
var casilla = document.getElementById('casilla').value;
var cadena = "muestra_texto.php?opcion="+casilla+'&anticache='+Math.random();
com.open("GET",cadena,true);
com.onreadystatechange = function(){
if(com.readyState==4){
document.getElementById('texto').value = com.responseText;
}
}
com.send(null);
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td><input type="checkbox" name="casilla" id="casilla" onClick="mostrar_texto()"></td>
</tr>
<tr>
<td><input type="text" name="texto" id="texto"></td>
</tr>
</table>
</form>
</body>
</html>
*************************************
muestra_texto.php
*************************************
<?php
if($_GET['opcion']=='on'){
echo("Está tildado");
}
else{
echo("No está tildado");
}
?>
Cómo puedo hacer para que cuando destilde la casilla, aparezca el texto "No está tildado"?
Muchas gracias,
Sandra
Son dos archivos: test.php y muestra_texto.php
***************************
test.php
***************************
<html>
<head>
<script>
function verificar_navegador(){
var com = null;
try{
com = new ActiveXObject("Msxml2.XMLHTTP");//versión más nueva de internet explorer
}
catch(e){
try{
com = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2){
com=new XMLHttpRequest();//para los otros navegadores
}
}
return com;
}
function mostrar_texto(){
var com = verificar_navegador();
var casilla = document.getElementById('casilla').value;
var cadena = "muestra_texto.php?opcion="+casilla+'&anticache='+Math.random();
com.open("GET",cadena,true);
com.onreadystatechange = function(){
if(com.readyState==4){
document.getElementById('texto').value = com.responseText;
}
}
com.send(null);
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td><input type="checkbox" name="casilla" id="casilla" onClick="mostrar_texto()"></td>
</tr>
<tr>
<td><input type="text" name="texto" id="texto"></td>
</tr>
</table>
</form>
</body>
</html>
*************************************
muestra_texto.php
*************************************
<?php
if($_GET['opcion']=='on'){
echo("Está tildado");
}
else{
echo("No está tildado");
}
?>
Cómo puedo hacer para que cuando destilde la casilla, aparezca el texto "No está tildado"?
Muchas gracias,
Sandra
Valora esta pregunta


0