Foros del Web » Programando para Internet » Javascript »

Formulario en Pestañas

Estas en el tema de Formulario en Pestañas en el foro de Javascript en Foros del Web. hola amigos la verdad es que necesito de su ayuda, el problema que tengo en estos momentos es que tengo un formulario de datos en ...
  #1 (permalink)  
Antiguo 30/09/2009, 11:29
 
Fecha de Ingreso: septiembre-2009
Mensajes: 16
Antigüedad: 14 años, 7 meses
Puntos: 0
Exclamación Formulario en Pestañas

hola amigos la verdad es que necesito de su ayuda, el problema que tengo en estos momentos es que tengo un formulario de datos en donde esta divido de la siguiente manera

Datos Personales, Datos laborales, Datos familiares, Datos Extras, Datos de Operador

El formulario es muy extenso y muy tedioso recorrelo con un scroll, quisiera poder tener unas pestañas(solapas) que me permita dividir el formulario en 4 partes pero que amedida que se llene cada parte no se pierdan los datos asi enviarlos todos a la base de datos.

Alguna solucion o ejemplo gracias.

Última edición por alancix; 30/09/2009 a las 13:04
  #2 (permalink)  
Antiguo 30/09/2009, 11:47
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 9 meses
Puntos: 1532
Respuesta: Formulario en Pestañas

tanto jQuery como mootols tienen plugins para hacerlas (tabs), pero simplemente son div's con display:none; organizados
  #3 (permalink)  
Antiguo 30/09/2009, 12:12
 
Fecha de Ingreso: septiembre-2009
Mensajes: 16
Antigüedad: 14 años, 7 meses
Puntos: 0
Respuesta: Formulario en Pestañas

Yo estoy trabajando bajo dreamweaver si he estado leyendo y hablan sobre DIV, la verdad si tuvieras alo diseñado parecido o ver el codigo. o alguna solucion rapida
  #4 (permalink)  
Antiguo 30/09/2009, 14:08
Avatar de Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: Formulario en Pestañas

Hola

Prueba esto que monte una tarde de Domingo con el aburrimiento

Código javascript:
Ver original
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. var ns4 = (document.layers)? true:false
  5. var ie4 = (document.all)? true:false
  6. var ns6 = (document.getElementById)? true:false
  7. var nivel = 1;
  8. var PosElementoAlto = 0 ;
  9. var Arr = [];
  10.  
  11. var info = {
  12. captura_objeto : function(idnombre) {
  13.     if (ns6)
  14.     {
  15.     return document.getElementById(idnombre);
  16.     }
  17.     else if (ie4)
  18.     {
  19.     return document.all[idnombre];
  20.     }
  21.     else if (ns4)
  22.     {
  23.     return document.layers[idnombre];
  24.     }
  25.     else
  26.     {
  27.     return null;
  28.     }
  29. },
  30.  
  31.  
  32. Evento : function(elemento,nomevento,funcion) {
  33.     if (elemento.attachEvent)
  34.     {
  35.         var fct=function(){
  36.             funcion.call(elemento,window.event);
  37.         }
  38.         elemento.attachEvent('on'+nomevento,fct);
  39.         return true;
  40.     }
  41.     else  
  42.         if (elemento.addEventListener)
  43.         {
  44.         elemento.addEventListener(nomevento,funcion,false);
  45.         return true;
  46.         }
  47.         else
  48.         return false;
  49. },
  50.  
  51.  
  52. init: function(){
  53. var ref = info.captura_objeto('lasLigas').getElementsByTagName('A');
  54.     for (var i = 0; i < ref.length; i++) {
  55. var infodiv = info.captura_objeto('info_menu_'+ref[i].id);
  56.         if (document.Element || document.body) {
  57.             info.altura = infodiv.scrollHeight;
  58.         } else {
  59.             info.altura = infodiv.clientHeight;
  60.         }
  61.             infodiv.style.display = 'none';
  62.             infodiv.style.zIndex = 0;
  63.                     info.Evento(ref[i], 'click', function() {info.efecto_largo(this.id)});
  64.     }
  65. },
  66.  
  67.  
  68. PosicionAbsolutaElemento: function(element)  {
  69. var window_height =  parseInt(((screen.height) / 2) - info.altura);
  70. var window_width = parseInt(((screen.width) / 2) - 150);
  71.  
  72.     if (typeof element == "string")
  73.         element = info.captura_objeto(element)
  74.             if (!element) return { top:0,left:0 };
  75. var y = 0;
  76. var x = 0;
  77.             while (element.offsetParent) {
  78.                     x += element.offsetLeft;
  79.                     y += element.offsetTop;
  80.                 element = element.offsetParent;
  81.      }
  82.     return {top:y, left:x, height:window_height, width: window_width};
  83.  
  84. },
  85.  
  86.    
  87. efecto_largo: function(id){
  88.             if(info.captura_objeto('info_menu_'+id).style.display == 'none'){
  89.                     clearInterval(info.intervalo);
  90.                 info.despliega_largo(id);
  91.         info.abierto_largo = false;
  92. //alert(info.abierto_largo);
  93.             }else{
  94.                     clearInterval(info.intervalo);
  95.                     info.recoge_largo(id);
  96.         info.abierto_largo = true;
  97. //alert(info.abierto_largo);
  98.             }
  99. },
  100.    
  101.  
  102. despliega_largo: function(id){
  103. Arr.unshift(id);
  104. //alert(Arr);
  105.     for (var i = 0; i < Arr.length; i++) {
  106. var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  107. var PosElemento = info.PosicionAbsolutaElemento(Arr[i]);
  108.         if (i == 0) {
  109. PosElementoAlto = PosElemento.top;
  110.             infodiv.style.height = '1px';
  111.             infodiv.style.display = 'block';
  112.             infodiv.style.zIndex = nivel;
  113.             infodiv.style.left = parseInt(PosElemento.width) +'px';
  114.             infodiv.style.top = parseInt(PosElemento.height - PosElementoAlto) +'px';
  115.                     info.intervalo = setInterval(function(){ info.redimenciona_largo(info.altura,id); }, 1);
  116.             nivel ++;
  117. //alert(parseInt(PosElementoAlto))
  118.         } else {
  119. var izq_arr = parseInt(20 * i) 
  120.             infodiv.style.left = parseInt(PosElemento.width - izq_arr) +'px';
  121.             infodiv.style.top = parseInt((PosElemento.height) - (PosElementoAlto + izq_arr)) +'px';
  122.         }
  123.     }
  124. },
  125.    
  126.  
  127. recoge_largo: function(id){
  128. //alert(id)
  129. var infodiv = info.captura_objeto('info_menu_'+id);
  130. var i, encaja;
  131.     for (i = 0; i < Arr.length; i++) {
  132.         if (Arr[i] == id) {
  133.                 encaja = i;
  134.     break;
  135.         }
  136.     }
  137.     for (var j = 0; j < Arr.length; j++) {
  138.         if (j > encaja ) {
  139. var infodiv2 = info.captura_objeto('info_menu_'+Arr[j]);
  140. var PosElemento = info.PosicionAbsolutaElemento('info_menu_'+Arr[j]);
  141.             infodiv2.style.left = parseInt(PosElemento.left + 20) +'px';
  142.             infodiv2.style.top = parseInt(PosElemento.top + 20) +'px';
  143.  
  144.         }
  145.     }
  146.     Arr.splice(encaja, 1);
  147.             infodiv.style.height = info.altura + 'px';
  148.     info.intervalo = setInterval(function(){ info.redimenciona_largo(0,id); }, 1);
  149. },
  150.    
  151.  
  152. redimenciona_largo: function(limite,id){
  153. var infodiv = info.captura_objeto('info_menu_'+id);
  154.     inicial = parseInt(infodiv.style.height);
  155.             actual = Math.ceil((limite - inicial) / 4);
  156.             inicial += actual;
  157.             infodiv.style.height = inicial + 'px';
  158.         if (parseInt(inicial) >= (limite - 5) && parseInt(inicial) <= (limite + 5)) {
  159.             if (info.abierto_largo == false) {
  160.                 infodiv.style.height = limite + 'px';
  161.                 clearInterval(info.intervalo);
  162.             } else {
  163.                 infodiv.style.height = '0px';
  164.                 infodiv.style.display = 'none';
  165.                 clearInterval(info.intervalo);
  166.             }
  167.         }
  168. },
  169.    
  170.  
  171. z_Index : function(id){
  172. // RECOGER
  173. var infodiv = info.captura_objeto('info_menu_'+id);
  174. var i, encaja;
  175.     for (i = 0; i < Arr.length; i++) {
  176.         if (Arr[i] == id) {
  177.                 encaja = i;
  178.     break;
  179.         }
  180.     }
  181. //alert(encaja);
  182.     for (var j = 0; j < Arr.length; j++) {
  183.         if (j > encaja) {
  184. var infodiv2 = info.captura_objeto('info_menu_'+Arr[j]);
  185. var PosElemento = info.PosicionAbsolutaElemento('info_menu_'+Arr[j]);
  186.             infodiv2.style.left = parseInt(PosElemento.left + 20) +'px';
  187.             infodiv2.style.top = parseInt(PosElemento.top + 20) +'px';
  188.  
  189.         }
  190.     }
  191.     Arr.splice(encaja, 1);
  192.  
  193.  
  194. //MOSTRAR
  195. Arr.unshift(id);
  196.  
  197.     for (var i = 0; i < Arr.length; i++) {
  198. var PosElemento = info.PosicionAbsolutaElemento(Arr[i]);
  199. var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  200. //if (PosElemento.top == 0) PosElemento.top = 9;
  201.         if (i == 0) {
  202.             infodiv.style.zIndex = nivel;
  203.             infodiv.style.left = parseInt(PosElemento.width) +'px';
  204.             infodiv.style.top = parseInt(PosElemento.height - (PosElemento.top + PosElementoAlto)) +'px';
  205.             nivel ++;
  206. //alert(parseInt(PosElementoAlto))
  207.         } else {
  208. //var infodiv = info.captura_objeto('info_menu_'+Arr[i]);
  209. var izq_arr = parseInt(20 * i)
  210.             infodiv.style.left = parseInt(PosElemento.width - izq_arr) +'px';
  211.             infodiv.style.top = parseInt(PosElemento.height - (PosElementoAlto + izq_arr)) +'px';
  212.         }
  213.     }
  214. },
  215.  
  216. abierto_largo : true,
  217. abierto_ancho : true
  218. }
  219.  
  220. info.Evento(window, 'load', info.init);
  221.  
  222.  
  223. function validaForm(f) {
  224. var ok = f.campo1.value != "";
  225. if (!ok) {
  226. alert("El campo nombre no puede estar vacio")
  227. return (false);
  228. } else {
  229. return (true);
  230. }
  231. }
  232. </script>
  233. </head>
  234. <body>
  235. <div id="lasLigas">
  236. <a href="javascript:void(0);" id="1">APARTADO 1</a> ||
  237. <a href="javascript:void(0);" id="2">APARTADO 2</a> ||
  238. <a href="javascript:void(0);" id="3">APARTADO 3</a> ||
  239. <a href="javascript:void(0);" id="4">APARTADO 4</a>
  240. </div>
  241.  
  242. <FORM action="pagina.asp" method="get" onsubmit="return  validaForm(this);">
  243.  
  244. <div id="info_menu_1" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  245. <span style="float:right;"><a href="#" onclick="info.z_Index(1)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(1)" title="Cierra">X</a></span>APARTADO 1<br /><br />
  246. NOMBRE: <input type="text" value="" id="campo1" name="campo1" /><br />
  247. APELLIDOS: <input type="text" value="" id="campo2" name="campo2" />
  248. </div>
  249.  
  250.  
  251. <div id="info_menu_2" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  252. <span style="float:right;"><a href="#" onclick="info.z_Index(2)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(2)" title="Cierra">X</a></span>APARTADO 2<br /><br />
  253. ESTUDIOS: <input type="text" value="" id="campo3" name="campo3" /><br />
  254. PROFESION: <input type="text" value="" id="campo4" name="campo4" />
  255. </div>
  256.  
  257.  
  258. <div id="info_menu_3" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  259. <span style="float:right;"><a href="#" onclick="info.z_Index(3)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(3)" title="Cierra">X</a></span>APARTADO 3<br /><br />
  260. DOMICILIO: <input type="text" value="" id="campo5" name="campo5" /><br />
  261. POBLACION: <input type="text" value="" id="campo6" name="campo6" />
  262. </div>
  263.  
  264.  
  265. <div id="info_menu_4" style="position:absolute; left:0px; top:0px; height:0px; width:400px; overflow:hidden; font:bold 10px Verdana, Helvetica, sans-serif; background-color:#FFFFFF; border: 1px solid #C9C9C9; border-width: 1px 1px 1px 1px;">
  266. <span style="float:right;"><a href="#" onclick="info.z_Index(4)" title="Traer al Frente"><></a> || <a href="#" onclick="info.efecto_largo(4)" title="Cierra">X</a></span>APARTADO 4<br /><br />
  267. ESTADO CIVIL: <br />
  268. Casado <input type="radio" value="casado" id="campo7" name="campo7" /><br />
  269. Soltero <input type="radio" value="soltero" id="campo7" name="campo7" />
  270. </div>
  271.  
  272. <input type="submit" value="enviar" />
  273. </FROM>
  274. </body>
  275. </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;" />
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 07:03.