Ver Mensaje Individual
  #2 (permalink)  
Antiguo 21/06/2010, 00:11
Avatar de rebouy
rebouy
 
Fecha de Ingreso: mayo-2010
Ubicación: Argentina
Mensajes: 21
Antigüedad: 14 años
Puntos: 0
Respuesta: Cambiar con un boton el color del fondo de un div

No entendi bien tu pregunta, pero creo que necesitas algo asi:
Código HTML:
Ver original
  1. <p>Elegi un color (Verde - Azul - Rojo)</p>
  2.  
  3. <input type="text" id="dato" maxlength="10"/><br />
  4. <input type="button" value="APLICAR" onclick="prueba()"/>
  5. <div id="prueba" style="width:100px;height:100px;background:black;color:white;">div prueba</div>
  6.  
  7.  
  8. function prueba()
  9. {
  10. var campo=document.getElementById("dato").value;
  11.  
  12. var prueba=document.getElementById("prueba");
  13. switch (campo) {
  14. case 'rojo': prueba.style.background="red";
  15. break;
  16. case 'verde':prueba.style.background="green";
  17. break;
  18. case 'azul':prueba.style.background="blue";
  19.  
  20. }
  21. }
Chau suerte!.