Respuesta: "Juntar" dos javascript El codigo queda reducido de la siguiente manera =P
Código Javascript :
Ver originalvar MyOptions = {adultos:['...', 'Contactos', 'Videos X', 'Tendencias'], arte:['...', 'Literatura', 'Cine', 'Fotografía'], ciencia:['...', 'Ingeniería', 'Medio Ambiente', 'Arquitectura'], compra:['...', 'Casa y Jardín', 'Animales', 'Automóviles'], deportes:['...', 'Automovilismo', 'Futbol', 'Tenis', 'Padel'], educacion:['...', 'Cursos a distancia', 'Idiomas', 'Colegios', 'Web educativas'], hogar:['...', 'Cocina', 'Muebles', 'Decoración', 'Electrodomésticos'], internet:['...', 'Informática', 'Alojamiento', 'Chat', 'Descargas'], Juegos:['...','Loterias-Quinielas', 'Videojuegos'], negocios:['...', 'Bares y Restaurantes', 'Fiestas', 'Asesorias', 'Limpieza'], salud:['...', 'Medicamentos', 'Medicina Alternativa', 'Dietética']} function cambiar(){ try{ var service = document.getElementById('servicios'); var Elements; var Printer='<select id="mes" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">'; var Sel = document.getElementById('meses'); switch(service.selectedIndex){ case 1: Elements = MyOptions.adultos; break; case 2: Elements = MyOptions.arte; break; case 3: Elements = MyOptions.ciencia; break; case 4: Elements = MyOptions.compra; break; case 5: Elements = MyOptions.deportes; break; case 6: Elements = MyOptions.educacion; break; case 7: Elements = MyOptions.hogar; break; case 8: Elements = MyOptions.internet; break; case 9: Elements = MyOptions.Juegos; break; case 10: Elements = MyOptions.negocios; break; case 11: Elements = MyOptions.salud; break; default: Elements = ['...']; break; } for(var i=0;i<Elements.length;i++){ Printer=Printer+'<option value="'+Elements[i]+'" selected>'+Elements[i]+'</option>' } Sel.innerHTML=Printer+'</select>'; var mes = document.getElementById('mes'); mes.value='...'; }catch(e){} }
ya implementado se ve así
<html>
<head>
<title>ejemplo</title>
<script>
var timer = setInterval('COUNT_CHARACTERS();', 10);
var Debugger;
var Proceded;
function COUNT_CHARACTERS(){
var MyElement = document.getElementById('Comentarios');
var Count = document.getElementById('Count');
Count.innerHTML = 'Comentarios: ('+MyElement.value.length+' / 99)';
if(MyElement.value.length > 99){
MyElement.value = MyElement.value.substring(0,99);
}
}
function VALIDATE_FIELDS(){
Debugger='Se han encontrado los siguientes errores: \n \n';
Proceded=true;
var Fields = ['Nombre', 'Direccion', 'Edad', 'Mail', 'Pais', 'campo_N...'];
for(var i=0; i<Fields.length;i++){
var MyField = document.getElementById(Fields[i]);
if(Fields[i] == 'Mail'){
if(MyField.value.indexOf('@')==-1){
Debugger=Debugger+'* El email proporcionado es incorrecto. \n';
Proceded=false;
}
}else if(Fields[i] == 'Nombre'){
if(MyField.value.length < 10 || MyField.value.length > 99){
Debugger=Debugger+'* El campo '+Fields[i]+' debe contener al menos 10 caracteres y menos de 99. \n';
Proceded=false;
}
}else{
if(MyField.value == ''){
Debugger=Debugger+'* El campo '+Fields[i]+' no puede estar vacio. \n';
Proceded=false;
}
}
}
if(Proceded){
document.forms["MyData"].submit();
}else{
alert(Debugger);
}
}
//-->
var MyOptions = {adultos:['...', 'Contactos', 'Videos X', 'Tendencias'], arte:['...', 'Literatura', 'Cine', 'Fotografía'], ciencia:['...', 'Ingeniería', 'Medio Ambiente', 'Arquitectura'], compra:['...', 'Casa y Jardín', 'Animales', 'Automóviles'], deportes:['...', 'Automovilismo', 'Futbol', 'Tenis', 'Padel'], educacion:['...', 'Cursos a distancia', 'Idiomas', 'Colegios', 'Web educativas'], hogar:['...', 'Cocina', 'Muebles', 'Decoración', 'Electrodomésticos'], internet:['...', 'Informática', 'Alojamiento', 'Chat', 'Descargas'], Juegos:['...','Loterias-Quinielas', 'Videojuegos'], negocios:['...', 'Bares y Restaurantes', 'Fiestas', 'Asesorias', 'Limpieza'], salud:['...', 'Medicamentos', 'Medicina Alternativa', 'Dietética']}
function cambiar(){
try{
var service = document.getElementById('servicios');
var Elements;
var Printer='<select id="mes" style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">';
var Sel = document.getElementById('meses');
switch(service.selectedIndex){
case 1:
Elements = MyOptions.adultos;
break;
case 2:
Elements = MyOptions.arte;
break;
case 3:
Elements = MyOptions.ciencia;
break;
case 4:
Elements = MyOptions.compra;
break;
case 5:
Elements = MyOptions.deportes;
break;
case 6:
Elements = MyOptions.educacion;
break;
case 7:
Elements = MyOptions.hogar;
break;
case 8:
Elements = MyOptions.internet;
break;
case 9:
Elements = MyOptions.Juegos;
break;
case 10:
Elements = MyOptions.negocios;
break;
case 11:
Elements = MyOptions.salud;
break;
default:
Elements = ['...'];
break;
}
for(var i=0;i<Elements.length;i++){
Printer=Printer+'<option value="'+Elements[i]+'" selected>'+Elements[i]+'</option>'
}
Sel.innerHTML=Printer+'</select>';
var mes = document.getElementById('mes');
mes.value='...';
}catch(e){}
}
</script>
</head>
<body>
<form name="MyData" action="archivo.php" method="post">
<label id="Count">Comentarios:</label><br /><textarea id="Comentarios">Aquí tus comentarios</textarea><br />
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="">Escojer</option>
<option value="Adultos">Adultos</option>
<option value="Arte y Literatura">Arte y Literatura</option>
<option value="Ciencia y Tecnología">Ciencia y Tecnología</option>
<option value="Compra-Venta">Compra-Venta</option>
<option value="Deportes">Deportes</option>
<option value="Educación">Educación</option>
<option value="Hogar">Hogar</option>
<option value="Internet">Internet</option>
<option value="Juegos">Juegos</option>
<option value="Negocios">Negocios</option>
<option value="Salud y Belleza">Salud y Belleza</option>
<option value="Sociedad">Sociedad</option>
<option value="Turismo y Viaje">Turismo y Viaje</option>
</select>
<br>
<div id="meses">
<select style="color:white;font-weight:bold;border-style: outset; border-width: 4px; border-color:#00FFFF;background:#000000;font-size:11pt;">
<option value="Enero" selected>...</option>
</select>
</div>
<input type="button" onClick="VALIDATE_FIELDS();" value="imprimir alerta" />
</form>
</body>
</html>
Es importante destacar que para rellenar automaticamente el segundo combobox, se agregó un <div> <div id="meses"> esto para indicar donde se va a imprimir el contenido
var Sel = document.getElementById('meses');
=D...
Espero que te sea de utilidad....
__________________ Se acepta Karma (:
Si Dios con nosotros, quien contra nosotros !! |