Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/04/2013, 14:05
jediap
 
Fecha de Ingreso: abril-2012
Mensajes: 42
Antigüedad: 12 años
Puntos: 1
Activar o desactivar checkbox dependiendo del otro

Buenas a todos, tengo un problema,quiero conseguir la funcionalidad del radiobutton con los checkbox.

El problema que me lo hace bien de c2 a c1 pero a la inversa no hace nada, se queda como bloqueado.

Este es mi html

Código HTML:
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="newjavascript.js" type="text/javascript"></script>
        <title>Prueba</title>
    </head>
    <body>
        <h1>Hola</h1>
        <p> Pulsa aqui para realizar una acción</p>
        <div id="grupoCheckBox">
            <p>C1</p>
            <input type="checkbox" id="check1" onclick="saludar();">
            <p>c2</p>
            <input type="checkbox" id="check2" onclick="saludar();"> 
        </div>
        <br>
        <br>
        <br>
        <br>
        <INPUT TYPE="BUTTON" VALUE="Guardar registro">
    </body>

</html> 

y este mi javascript

Código:
function saludar() {
    var checkbox1 = document.getElementById("check1");
    var checkbox2 = document.getElementById("check2");

    if (checkbox1.checked == true) {
        checkbox2.checked = false;
    }else if(checkbox2.checked == true){
        checkbox1.checked =false;
    }
   
}

Muchas gracias.