Ver Mensaje Individual
  #2 (permalink)  
Antiguo 11/12/2011, 15:00
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: checkbox "botón" con imagenes

@besotico, vas a tener problemas con esa estructura, suponiendo que los usuarios destilden el checkbox.

Para hacer o no el cambio, primero deberías comprobar el estado del checkbox.

Usa esto
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>chk img</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8.  
  9. function testchk(){
  10. var valor = document.getElementById('chk_id').checked;
  11. alert(valor);
  12. }
  13. function check(checkboxid,imag,defecto) {  
  14. var valor = document.getElementById(checkboxid).checked;
  15.  
  16. if (valor == false){
  17. document.getElementById(checkboxid).checked = true;  
  18. document.getElementById(imag).src = imag + ".jpg";  
  19. }else{
  20. document.getElementById(checkboxid).checked = false;  
  21. document.getElementById(imag).src = defecto;  
  22. }
  23.  
  24. }  
  25. //]]>
  26. </head>
  27. <img src="uno.jpg" onclick="check('chk_id',this.id,'uno.jpg');" width="50" height="50" id="lupa" alt="" name="lupa" />
  28. <form action="#">
  29. <p>
  30. <input type="checkbox" id="chk_id" value="si" />
  31. </p>
  32. </form>
  33. <p>
  34. <br />
  35.  <a href="#" onclick="testchk();">Verificar</a>
  36. </p>
  37. </body>
  38. </html>

Algunos detalles, para cargar la imagen cuando esta activo uso el id=lupa, ya que mi imagen se llama lupa.jpg.
paso tres parámetros a la función, el primero es el checkbox que debe afectar, el segundo, el id de la imagen para reemplazar por id + .jpg y el tercero para restablecer a la imagen por defecto cuando desmarcan, para verificar te deje un link y otra función testchk();
Cuando hagas las pruebas no uses el checkbox, usá siempre la imagen, y una vez verificado, simplemente oculta el checkbox con style="display: none;"
eso sí, tendría que hacer tus imágenes bien descriptivas

Saludos

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.