Ver Mensaje Individual
  #11 (permalink)  
Antiguo 19/05/2011, 09:27
miriamgomez
 
Fecha de Ingreso: abril-2008
Mensajes: 348
Antigüedad: 16 años
Puntos: 1
Respuesta: "Juntar" dos javascript

Código PHP:
Ver original
  1. <html>
  2. <head>
  3. <title>ejemplo</title>
  4. <script>
  5. var timer = setInterval('COUNT_CHARACTERS();', 10);
  6. var Debugger;
  7. var Proceded;
  8.  
  9. function COUNT_CHARACTERS(){
  10.     var MyElement = document.getElementById('Comentarios');
  11.     var Count = document.getElementById('Count');
  12.     Count.innerHTML = 'Comentarios: ('+MyElement.value.length+' / 99)';
  13.     if(MyElement.value.length > 99){
  14.         MyElement.value = MyElement.value.substring(0,99);
  15.     }
  16. }
  17.  
  18. function VALIDATE_FIELDS(){
  19.   Debugger='Se han encontrado los siguientes errores: \n \n';
  20.   Proceded=true;
  21.   var Fields = ['Comentarios','Nombre', 'Direccion', 'Edad', 'Mail', 'Pais', 'campo_N...'];
  22.   for(var i=0; i<Fields.length;i++){
  23.       var MyField = document.getElementById(Fields[i]);
  24.       if(Fields[i] == 'Mail'){
  25.           if(MyField.value.indexOf('@')==-1){
  26.               Debugger=Debugger+'* El email proporcionado es incorrecto. \n';
  27.               Proceded=false;
  28.           }
  29.       }else if(Fields[i] == 'Comentarios'){
  30.           if(MyField.value.length < 10 || MyField.value.length > 99){
  31.               Debugger=Debugger+'* El campo '+Fields[i]+' debe contener al menos 10 caracteres y menos de 99. \n';
  32.               Proceded=false;
  33.           }
  34.       }else{
  35.         if(MyField.value == ''){
  36.               Debugger=Debugger+'* El campo '+Fields[i]+' no puede estar vacio. \n';
  37.               Proceded=false;
  38.           }  
  39.       }
  40.   }
  41.   if(Proceded){
  42.       document.forms["MyData"].submit();
  43.   }else{
  44.       alert(Debugger);
  45.   }
  46. }
  47. </script>
  48. <script type="text/JavaScript">
  49.  
  50.  
  51. //-->
  52. function cambiar()
  53. {
  54. var index=document.forms.formulario.servicios.selectedIndex;
  55.  
  56. formulario.meses.length=0;
  57.  
  58. if(index==2) Arte();
  59. if(index==3) Ciencia();
  60. if(index==4) Compra();
  61. if(index==5) Deportes();
  62. if(index==10) Negocios();
  63. if(index==6) Educacion();
  64. if(index==7) Hogar();
  65. if(index==8) Internet();
  66. if(index==9) Juegos();
  67. if(index==11) Salud();
  68. if(index==1) Adultos();
  69.  
  70. }
  71. function Arte(){
  72. opcion0=new Option("...","...","defauldSelected");
  73. opcion1=new Option("Literatura","Literatura");
  74. opcion2=new Option("Cine","Cine");
  75. opcion3=new Option("Fotografía","Fotofrafía");
  76.  
  77. document.forms.formulario.meses.options[0]=opcion0;
  78. document.forms.formulario.meses.options[1]=opcion1;
  79. document.forms.formulario.meses.options[2]=opcion2;
  80. document.forms.formulario.meses.options[3]=opcion3;
  81. }
  82. function Ciencia(){
  83. opcion0=new Option("...","...","defauldSelected");
  84. opcion1=new Option("Ingeniería","Ingeniería");
  85. opcion2=new Option("Media Ambiente","Medio Ambiente");
  86. opcion3=new Option("Arquitectura","Arquitectura");
  87.  
  88.  
  89. document.forms.formulario.meses.options[0]=opcion0;
  90. document.forms.formulario.meses.options[1]=opcion1;
  91. document.forms.formulario.meses.options[2]=opcion2;
  92. document.forms.formulario.meses.options[3]=opcion3;
  93.  
  94. }
  95.  
  96. function Compra(){
  97. opcion0=new Option("...","...","defauldSelected");
  98. opcion1=new Option("Casa y Jardín","Casa y Jardín");
  99. opcion2=new Option("Animales","Animales");
  100. opcion3=new Option("Automoviles","Automoviles");
  101.  
  102.  
  103.  
  104. document.forms.formulario.meses.options[0]=opcion0;
  105. document.forms.formulario.meses.options[1]=opcion1;
  106. document.forms.formulario.meses.options[2]=opcion2;
  107. document.forms.formulario.meses.options[3]=opcion3;
  108.  
  109. }
  110.  
  111. function Deportes(){
  112. opcion0=new Option("...","...","defauldSelected");
  113. opcion1=new Option("Automovilismo","Automovilismo");
  114. opcion2=new Option("Futbol","Futbol");
  115. opcion3=new Option("Tenis","Tenis");
  116. opcion4=new Option("Padel","Padel");
  117.  
  118.  
  119. document.forms.formulario.meses.options[0]=opcion0;
  120. document.forms.formulario.meses.options[1]=opcion1;
  121. document.forms.formulario.meses.options[2]=opcion2;
  122. document.forms.formulario.meses.options[3]=opcion3;
  123. document.forms.formulario.meses.options[4]=opcion4;
  124.  
  125. }
  126. function Negocios(){
  127. opcion0=new Option("...","...","defauldSelected");
  128. opcion1=new Option("Bares y Restaurantes","Bares y Restaurantes");
  129. opcion2=new Option("Fiestas","Fiestas");
  130. opcion3=new Option("Asesorias","Asesorias");
  131. opcion4=new Option("Limpiezas","Limpiezas");
  132.  
  133.  
  134. document.forms.formulario.meses.options[0]=opcion0;
  135. document.forms.formulario.meses.options[1]=opcion1;
  136. document.forms.formulario.meses.options[2]=opcion2;
  137. document.forms.formulario.meses.options[3]=opcion3;
  138. document.forms.formulario.meses.options[4]=opcion4;
  139.  
  140. }
  141. function Educacion(){
  142. opcion0=new Option("...","...","defauldSelected");
  143. opcion1=new Option("Cursos a distancia","Curso a distancia");
  144. opcion2=new Option("Idiomas","Idiomas");
  145. opcion3=new Option("Colegios","Colegios");
  146. opcion4=new Option("Web educativas","Web educativas");
  147.  
  148.  
  149. document.forms.formulario.meses.options[0]=opcion0;
  150. document.forms.formulario.meses.options[1]=opcion1;
  151. document.forms.formulario.meses.options[2]=opcion2;
  152. document.forms.formulario.meses.options[3]=opcion3;
  153. document.forms.formulario.meses.options[4]=opcion4;
  154.  
  155. }
  156. function Hogar(){
  157. opcion0=new Option("...","...","defauldSelected");
  158. opcion1=new Option("Cocina","Cocina");
  159. opcion2=new Option("Muebles","Muebles");
  160. opcion3=new Option("Decoración","Decoracion");
  161. opcion4=new Option("Electrodomésticos","Electrodomésticos");
  162.  
  163.  
  164. document.forms.formulario.meses.options[0]=opcion0;
  165. document.forms.formulario.meses.options[1]=opcion1;
  166. document.forms.formulario.meses.options[2]=opcion2;
  167. document.forms.formulario.meses.options[3]=opcion3;
  168. document.forms.formulario.meses.options[4]=opcion4;
  169.  
  170. }
  171. function Internet(){
  172. opcion0=new Option("...","...","defauldSelected");
  173. opcion1=new Option("Informática","Informática");
  174. opcion2=new Option("Alojamiento","Alojamiento");
  175. opcion3=new Option("Chat","Chat");
  176. opcion4=new Option("Descargas","Descargas");
  177.  
  178.  
  179. document.forms.formulario.meses.options[0]=opcion0;
  180. document.forms.formulario.meses.options[1]=opcion1;
  181. document.forms.formulario.meses.options[2]=opcion2;
  182. document.forms.formulario.meses.options[3]=opcion3;
  183. document.forms.formulario.meses.options[4]=opcion4;
  184.  
  185. }
  186. function Juegos(){
  187. opcion0=new Option("...","...","defauldSelected");
  188. opcion1=new Option("Loterias-Quinielas","loterias-Quinielas");
  189. opcion2=new Option("Videojuegos","Videojuegos");
  190.  
  191.  
  192.  
  193.  
  194. document.forms.formulario.meses.options[0]=opcion0;
  195. document.forms.formulario.meses.options[1]=opcion1;
  196. document.forms.formulario.meses.options[2]=opcion2;
  197.  
  198.  
  199. }
  200. function Salud(){
  201. opcion0=new Option("...","...","defauldSelected");
  202. opcion1=new Option("Medicamentos","Medicamentos");
  203. opcion2=new Option("Medicina Alternativa","Medicina Alternativa");
  204. opcion3=new Option("Dietética","Dietética");
  205. document.forms.formulario.meses.options[0]=opcion0;
  206. document.forms.formulario.meses.options[1]=opcion1;
  207. document.forms.formulario.meses.options[2]=opcion2;
  208. document.forms.formulario.meses.options[3]=opcion3;
  209. }
  210. function Adultos(){
  211. opcion0=new Option("...","...","defauldSelected");
  212. opcion1=new Option("Contactos","Contactos");
  213. opcion2=new Option("Videos X","Videos X");
  214. opcion3=new Option("Tendencias","Tendencias");
  215.  
  216. document.forms.formulario.meses.options[0]=opcion0;
  217. document.forms.formulario.meses.options[1]=opcion1;
  218. document.forms.formulario.meses.options[2]=opcion2;
  219. document.forms.formulario.meses.options[3]=opcion3;
  220. }
  221. </script>
  222.  
  223. </head>
  224. <body>
  225. <form name="MyData" action="archivo.php" method="post">
  226.     <label id="Count">Comentarios:</label><br /><textarea id="Comentarios">Aqu&#237; tus comentarios</textarea><br />
  227.    Nombre:<br /><input type="text" id="Nombre" /><br />
  228.     Direccion:<br /><input type="text" id="Direccion" /><br />
  229.     Edad:<br /><input type="text" id="Edad" /><br />
  230.     E-Mail:<br /><input type="text" id="Mail" /><br />
  231.     Pais:<br /><input type="text" id="Pais" /><br />
  232.     Campo_N...:<br /><input type="text" id="campo_N..." /><br />
  233.    
  234.  <select name="servicios" OnChange="cambiar()" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">
  235.             <option value="">Escojer</option>
  236.             <option value="Adultos">Adultos</option>
  237.             <option value="Arte y Literatura">Arte y Literatura</option>
  238.             <option value="Ciencia y Tecnolog&iacute;a">Ciencia y Tecnolog&iacute;a</option>
  239.             <option value="Compra-Venta">Compra-Venta</option>
  240.             <option value="Deportes">Deportes</option>
  241.             <option value="Educaci&oacute;n">Educaci&oacute;n</option>
  242.             <option value="Hogar">Hogar</option>
  243.             <option value="Internet">Internet</option>
  244.             <option value="Juegos">Juegos</option>
  245.             <option value="Negocios">Negocios</option>
  246.             <option value="Salud y Belleza">Salud y Belleza</option>
  247.                      </select>
  248.        <br>
  249.  
  250.           <select name="meses" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">
  251.             <option value="Enero" selected>...</option>
  252.           </select>
  253.  
  254.     <input type="button" onClick="VALIDATE_FIELDS();" value="imprimir alerta" />
  255. </form>
  256. </body>
  257. </html>