Foros del Web » Programando para Internet » Javascript »

No funciona en IE

Estas en el tema de No funciona en IE en el foro de Javascript en Foros del Web. Tengo un ckech box que al pincharlo(selecionarlo) <td><input type="checkbox" name="checkbox" id="chk1" onclick="contar()" /> function contar() { if(document.getElementById("chk1").checked){ document.getElementById("div1").style.display='blo ck'; document.getElementById("uid_4234").checked=true; }else{ document.getElementById("div1").style.display='non e'; document.getElementById("uid_4234").checked=false; } ...
  #1 (permalink)  
Antiguo 17/06/2009, 01:47
 
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 352
Antigüedad: 15 años, 7 meses
Puntos: 5
No funciona en IE

Tengo un ckech box que al pincharlo(selecionarlo)

<td><input type="checkbox" name="checkbox" id="chk1" onclick="contar()" />

function contar() {

if(document.getElementById("chk1").checked){
document.getElementById("div1").style.display='blo ck';
document.getElementById("uid_4234").checked=true;
}else{
document.getElementById("div1").style.display='non e';
document.getElementById("uid_4234").checked=false;
}

Al seleccionar el check me muestra un div y marca seleccionado otro check, en firefox me va perfecto pero con IE me dice que esperaba un objeto y no funciona...
Necesito ayuda por favor.
  #2 (permalink)  
Antiguo 17/06/2009, 05:18
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: No funciona en IE

Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function contar(obj) {
	if(obj.checked){
		document.getElementById("div1").style.display='block';
		document.getElementById("uid_4234").checked=true;
	}else{
		document.getElementById("div1").style.display='none';
		document.getElementById("uid_4234").checked=false;
	}
}
</script>

</head>

<body>
<td><input type="checkbox" name="chk1" id="chk1" onclick="contar(this)" />

<div id="div1" style="display: none"><input type="checkbox" name="uid_4234" id="uid_4234" />Hola soy la div</div>
</body>
</html> 
Ahí va...

Quim
  #3 (permalink)  
Antiguo 18/06/2009, 01:31
 
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 352
Antigüedad: 15 años, 7 meses
Puntos: 5
Respuesta: No funciona en IE

Tengo un pequeño problema...y es que son 7 check no uno solo, te envie un cacho de código como ejemplo...

Tengo que ver el obj que check es realmente....:D

Si me puedes ayudar...muchas gracias.

Son 7 check con 7 div y otros 7 check que se seleccionan segun los primeros...

Muchas gracias...

<td><input type="checkbox" name="chk1" id="chk1"
onclick="contar()" />
<div id="div1" style="display: block;">


<td><input type="checkbox" name="chk2" id="chk2"
onclick="contar()" />
<div id="div2" style="display: block;">

.... asi hasta 7


function contar() {
//ch1
if(document.getElementById("chk1").checked){

document.getElementById("div1").style.display='blo ck';
document.getElementById("pfbCh01").checked=true;
}else{
document.getElementById("div1").style.display='non e';
document.getElementById("pfbCh01").checked=false;
}
//ch2
if(document.getElementById("chk2").checked){

document.getElementById("div2").style.display='blo ck';
document.getElementById("pfbCh02").checked=true;
}else{
document.getElementById("div2").style.display='non e';
document.getElementById("pfbCh02").checked=false;
}

...asi hasta siete
  #4 (permalink)  
Antiguo 22/06/2009, 02:32
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 16 años, 1 mes
Puntos: 574
Respuesta: No funciona en IE

Código HTML:
<td><input type="checkbox" name="chk1" id="chk1"
onclick="contar(this)" />
<div id="div1" style="display: block;">


<td><input type="checkbox" name="chk2" id="chk2"
onclick="contar(this)" />
<div id="div2" style="display: block;"> 

contar(this)!!!


.... asi hasta n


Código js:
Ver original
  1. function contar(obj) {
  2.         var sufijo=obj.id.substr(3,1);
  3.     if(obj.checked){
  4.         document.getElementById("div"+ sufijo).style.display='block';
  5.         document.getElementById("uid_4234" + sufijo).checked=true;
  6.     }else{
  7.         document.getElementById("div"+ sufijo).style.display='none';
  8.         document.getElementById("uid_4234"+ sufijo).checked=false;
  9.     }
  10. }

En el caso de la div esta claro que ya tienes el sufijo con lo que no tienes que tener problemas, en el caso de segundo chk quizas tendras que cambiar algo para poder usar esta estrategia....

Hacerlo así te asegura que si un dia en vez de ser 7 chk son otro numero (mayor o menor) no tendras que preocuparte de cambiar el codigo....

Quim
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:27.