Respuesta: "Juntar" dos javascript Este mismo código funciona para el mismo formulario
Código Javascript :
Ver originalvar timer=setInterval("COUNT_CHARACTERS();",10),Debugger,Proceded;function COUNT_CHARACTERS(){var b=document.getElementById("Comentarios");document.getElementById("Count").innerHTML="Comentarios: ("+b.value.length+" / 99)";if(b.value.length>99)b.value=b.value.substring(0,99)} function VALIDATE_FIELDS(){Debugger="Se han encontrado los siguientes errores: \n \n";Proceded=!0;for(var b=["Nombre","Direccion","Edad","Mail","Pais","campo_N..."],a=0;a<b.length;a++){var c=document.getElementById(b[a]);if(b[a]=="Mail")c.value.indexOf("@")==-1&&(Debugger+="* El email proporcionado es incorrecto. \n",Proceded=!1);else if(b[a]=="Nombre"){if(c.value.length<10||c.value.length>99)Debugger=Debugger+"* El campo "+b[a]+" debe contener al menos 10 caracteres y menos de 99. \n",Proceded=!1}else c.value== ""&&(Debugger=Debugger+"* El campo "+b[a]+" no puede estar vacio. \n",Proceded=!1)}Proceded?document.forms.MyData.submit():alert(Debugger)} var MyOptions={adultos:["...","Contactos","Videos X","Tendencias"],arte:["...","Literatura","Cine","Fotograf\u00eda"],ciencia:["...","Ingenier\u00eda","Medio Ambiente","Arquitectura"],compra:["...","Casa y Jard\u00edn","Animales","Autom\u00f3viles"],deportes:["...","Automovilismo","Futbol","Tenis","Padel"],educacion:["...","Cursos a distancia","Idiomas","Colegios","Web educativas"],hogar:["...","Cocina","Muebles","Decoraci\u00f3n","Electrodom\u00e9sticos"],internet:["...","Inform\u00e1tica","Alojamiento", "Chat","Descargas"],Juegos:["...","Loterias-Quinielas","Videojuegos"],negocios:["...","Bares y Restaurantes","Fiestas","Asesorias","Limpieza"],salud:["...","Medicamentos","Medicina Alternativa","Diet\u00e9tica"]}; function cambiar(){try{var b=document.getElementById("servicios"),a,c='<select id="mes" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">',d=document.getElementById("meses");switch(b.selectedIndex){case 1:a=MyOptions.adultos;break;case 2:a=MyOptions.arte;break;case 3:a=MyOptions.ciencia;break;case 4:a=MyOptions.compra;break;case 5:a=MyOptions.deportes;break;case 6:a=MyOptions.educacion;break;case 7:a=MyOptions.hogar; break;case 8:a=MyOptions.internet;break;case 9:a=MyOptions.Juegos;break;case 10:a=MyOptions.negocios;break;case 11:a=MyOptions.salud;break;default:a=["..."]}for(b=0;b<a.length;b++)c=c+'<option value="'+a[b]+'" selected>'+a[b]+"</option>";d.innerHTML=c+"</select>";document.getElementById("mes").value="..."}catch(e){}};
te recomiendo utilizarlo cuando vayas a liberar el proyecto.. =D
y quedaria algo así
Código HTML:
Ver originalvar timer=setInterval("COUNT_CHARACTERS();",10),Debugger,Proceded;function COUNT_CHARACTERS(){var b=document.getElementById("Comentarios");document.getElementById("Count").innerHTML="Comentarios: ("+b.value.length+" / 99)";if(b.value.length>99)b.value=b.value.substring(0,99)} function VALIDATE_FIELDS(){Debugger="Se han encontrado los siguientes errores: \n \n";Proceded=!0;for(var b=["Nombre","Direccion","Edad","Mail","Pais","campo_N..."],a=0;a<b.length;a++){var c=document.getElementById(b[a]);if(b[a]=="Mail")c.value.indexOf("@")==-1&&(Debugger+="* El email proporcionado es incorrecto. \n",Proceded=!1);else if(b[a]=="Nombre"){if(c.value.length<10||c.value.length>99)Debugger=Debugger+"* El campo "+b[a]+" debe contener al menos 10 caracteres y menos de 99. \n",Proceded=!1}else c.value== ""&&(Debugger=Debugger+"* El campo "+b[a]+" no puede estar vacio. \n",Proceded=!1)}Proceded?document.forms.MyData.submit():alert(Debugger)} var MyOptions={adultos:["...","Contactos","Videos X","Tendencias"],arte:["...","Literatura","Cine","Fotograf\u00eda"],ciencia:["...","Ingenier\u00eda","Medio Ambiente","Arquitectura"],compra:["...","Casa y Jard\u00edn","Animales","Autom\u00f3viles"],deportes:["...","Automovilismo","Futbol","Tenis","Padel"],educacion:["...","Cursos a distancia","Idiomas","Colegios","Web educativas"],hogar:["...","Cocina","Muebles","Decoraci\u00f3n","Electrodom\u00e9sticos"],internet:["...","Inform\u00e1tica","Alojamiento", "Chat","Descargas"],Juegos:["...","Loterias-Quinielas","Videojuegos"],negocios:["...","Bares y Restaurantes","Fiestas","Asesorias","Limpieza"],salud:["...","Medicamentos","Medicina Alternativa","Diet\u00e9tica"]}; function cambiar(){try{var b=document.getElementById("servicios"),a,c=' <select id="mes" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">',d=document.getElementById("meses");switch(b.selectedIndex){case 1:a=MyOptions.adultos;break;case 2:a=MyOptions.arte;break;case 3:a=MyOptions.ciencia;break;case 4:a=MyOptions.compra;break;case 5:a=MyOptions.deportes;break;case 6:a=MyOptions.educacion;break;case 7:a=MyOptions.hogar; break;case 8:a=MyOptions.internet;break;case 9:a=MyOptions.Juegos;break;case 10:a=MyOptions.negocios;break;case 11:a=MyOptions.salud;break;default:a=["..."]}for(b=0;b <a.length;b++)c=c+'<option value="'+a[b]+'" selected>'+a[b]+" </option>";d.innerHTML=c+" </select>";document.getElementById("mes").value="..."}catch(e){}}; <form name="MyData" action="archivo.php" method="post"> Nombre: <br /><input type="text" id="Nombre" /><br />Direccion: <br /><input type="text" id="Direccion" /><br />Edad: <br /><input type="text" id="Edad" /><br />E-Mail: <br /><input type="text" id="Mail" /><br />Pais: <br /><input type="text" id="Pais" /><br />Campo_N...: <br /><input type="text" id="campo_N..." /><br /> <select name="servicios" id="servicios" OnChange="cambiar()" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;"> <option value="Arte y Literatura">Arte y Literatura </option> <option value="Ciencia y Tecnología">Ciencia y Tecnolog ía </option> <select style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;"> <input type="button" onClick="VALIDATE_FIELDS();" value="imprimir alerta" />
Menos Líneas de código, y menos entendible también, pero para fines prácticos funciona mejor....
SALUDOS y EXITO !!
__________________ Se acepta Karma (:
Si Dios con nosotros, quien contra nosotros !! |