Ver Mensaje Individual
  #6 (permalink)  
Antiguo 27/07/2010, 15:16
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Problema con onblur y capa que se muestra

Hola

Un ejemplo completo
Código Javascript:
Ver original
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. #contenedor div.seleccionado {font-weight:bold; background:#F0F0F0; color:#FF6600;}
  5. #contenedor div.deseleccionado {background:#FFFFFF; color:#000000;}
  6. #contenedor div{font:11px verdana; color:#000000; cursor:pointer; text-align:left; padding:2px 5px;}
  7.  
  8. .capa {
  9. background: #FFFFFF;
  10. border:1px solid rgb(120,120,120);
  11. width: 144px;
  12. _width: 146px;
  13. text-align: left;
  14. position: absolute;
  15. top: 30px;
  16. _top:38px;
  17. left: 117px;
  18. _left: 119px;
  19. }
  20. </style>
  21. <script type="text/javascript">
  22. var SelUsuario = {
  23.  
  24. Evento: function (elemento,nomevento,funcion) {
  25.   if (elemento.attachEvent)
  26.   {
  27.       var f=function(){
  28.         funcion.call(elemento,window.event);
  29.     }
  30.     elemento.attachEvent('on'+nomevento,f);
  31.     return true;
  32.   }
  33.   else  
  34.     if (elemento.addEventListener)
  35.     {
  36.       elemento.addEventListener(nomevento,funcion,false);
  37.       return true;
  38.     }
  39.     else
  40.       return false;
  41. },
  42.  
  43.  
  44.  
  45. init: function(){
  46. var elem1 = document.getElementById("txt");
  47. var elem2 = document.getElementById("contenedor");
  48.         SelUsuario.Evento(elem1, 'click', SelUsuario.Muestra);
  49.         SelUsuario.Evento(elem2, 'mouseover', SelUsuario.Seleccionar);
  50.     },
  51.  
  52.  
  53.  
  54. Muestra: function () {
  55.     document.getElementById("contenedor").style.display= "block";
  56. },
  57.  
  58.  
  59.  
  60. Seleccionar: function () {
  61. var ref = document.getElementById(this.id).getElementsByTagName('DIV');
  62. for (var i = 0; i < ref.length; i++) {
  63.  
  64. SelUsuario.Evento(ref[i], 'mousedown', function() {
  65. SelUsuario.Pegar(this.id);
  66. })  
  67.  
  68.  
  69. SelUsuario.Evento(ref[i], 'mouseover',  function() {
  70. SelUsuario.Marcar(this.id);
  71. })
  72. }
  73.  
  74. SelUsuario.Evento(window, 'mouseup', SelUsuario.Cerrar);
  75.  
  76. },
  77.  
  78.  
  79.  
  80. Pegar: function (valor) {
  81. var obj = document.getElementById("contenedor")
  82.         document.getElementById("txt").value = valor;
  83.                 if (obj.style.display == "block"); obj.style.display= "none";      
  84. },
  85.  
  86.  
  87.  
  88. Marcar: function (id) {
  89. var selecionado = document.getElementById(id);
  90. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  91. for (var i = 0; i <= ref.length-1; i++) {
  92. if (ref[i].id != id) {
  93. ref[i].className = "deseleccionado";
  94. selecionado.className = "seleccionado";
  95. }
  96. }
  97. },
  98.  
  99.  
  100. Cerrar: function () {  
  101. var obj = document.getElementById("contenedor")
  102.             if (obj.style.display == "block"); obj.style.display= "none";  
  103.    
  104. }
  105. }
  106.  
  107.  
  108. SelUsuario.Evento(window, 'load', SelUsuario.init);
  109. </script>
  110. </head>
  111. <body>
  112. <form method="post" action="">
  113. Nombre Usuario: <input type="text" name="txt" id="txt" value="" autocomplete="off" tabindex="1" />
  114. <div id="contenedor" class="capa" style="display:none;">
  115. <div id="pinchu" class="seleccionado">pinchu</div>
  116. <div id="Adler" class="">Adler</div>
  117. <div id="caricato" class="">caricato</div>
  118. <div id="u_golman" class="">U_Goldman</div>
  119. </div>
  120. <input type="submit" value="Enviar">
  121. </form>
  122. </body>
  123. </html>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />