David Golightly escribió:
Winston wrote:
>I want to changue the stylesheet for this page.
Why the form select doesn't work?
link id="est" rel="stylesheet" type="text/css" href="est.css">
function Changue() {
var posibles = document.forms[0].XXX;
document.getElementById("est").href=posibles.opti ons[posibles.selectedIndex].value;
}
<form>
¿Changue to <select name="XXX" onChangue="Changue()">
<option selected value"estilo1.css"Estilo 1? </option>
<option value"estilo2.css"Estilo 2? </option>
<option value"estilo3.css"Estilo 3? </option>
</select>
</form>
First off, It's "onchange" not "onChangue". The word does not have a
"u" in it.
Also, what's going on with your HTML? Where's your "body" tag?
Where's your "html" tag? Why do you have script just there, not in a
"script" tag? Why do you have value"estilo1.css" - you need to have
value="estilo1.css" with an "=" between the attribute and the value.
Fix these things and this will work for you. But more troubling is
that these are all very basic things - go get a book on HTML and learn
HTML before starting to learn JavaScript. You really need to have a
solid HTML foundation before starting JavaScript.
Good luck,
David
Sorry, I didn't want to paste spanish code.
But you help me a lot with the onchange!
Thanks!
<html>
<head>
<title>Javascript 1 - document.write...</title>
</head>
<link id="estilos" rel="stylesheet" type="text/css" href="estilo2.css">
<script languaje="JavaScript">
function verifica(numero, cantidad) {
var sms = "Debe Ingresar un entero";
if (isNaN(numero)) {
document.getElementById("error1").innerHTML = "Debe Ingresar
un entero";
return false;
}
if (isNaN(cantidad)) {
document.getElementById("error2").innerHTML = "Debe Ingresar
un entero";
return false;
}
else
return true;
}
/* Genera las tablas de multiplicar y agrego otras operaciones, una fila
por cada ejecucion del for */
function generar_tabla(del_form) {
var salida = "";
var m = del_form.multiplicador.value;
var cantidad = del_form.cantidad.value;
m = parseInt(m)
cantidad = parseInt(cantidad)
if (verifica(m, cantidad)) {
salida ="<html><head><title>Codigo generado por una linea
for!</title></head><link rel='stylesheet' type='text/css'
href='estilo2.css'>"
salida +="<table border='5' width='95%' align='center'
cellspacing='8' cellpadding='10'>"
salida
+="<tr><th>Multiplica</th><th>Suma</th><th>Resta</th><th>Divide</th></tr>"
salida +="<tr align='center'><td</td<td</td> <td></td>
<td></td</tr>"
for (var i=1; i<=cantidad; i++)
salida
+="<tr><td>"+i+"*"+m+"="+(i*m)+"</td><td>"+i+"+"+m+"="+(i+m)+"</td><td>"+i+"-"+m+"="+(i-m)+"</td><td>"+i+"/"+m+"="+(i/m)+"</td></tr>"
salida += "</table></body</html>"
document.write(salida);
return true;
}
else {
return false;
}
}
function Cambiar() {
/* Es el primer Formulario de la pagina */
var posibles = document.forms[0].Seleccionar;
document.getElementById("estilos").href=posibles.o ptions[posibles.selectedIndex].value;
}
</script>
<body>
<div id="Menu">
<hr/>
<ul>
<li><a href="objetivo.html" title="Objetivo">Introduccion</a>
<li><a href="cv.html" title="Texto + Listas -
(C.V.)">C.V</a></li>
<li><a href="multimedia.html" title="Multimedia">Multimedia</a></li>
<li><a href="dondeestuve.html" title="Enlaces">Enlaces</a>
<li><a href="preguntas.html" title="Preguntas">Preguntas</a><ul>
<li><a href="preg_html.html" title="Preguntas sobre
HTML">HTML</a></li>
<li><a href="preg_css.html" title="Preguntas sobre
CSS">CSS</a></li>
<li><a href="preg_javascript.html" title="Preguntas sobre
JavaScript">JavaScript</a></li>
<li><a href="preg_php.html" title="Preguntas sobre
PHP">PHP</a></li></ul>
<li><a href="horarios.html" title="Horario de clase">Horario</a><ul>
<li><a href="horario1.html" title="Horario
(Tablas)">Horario (Tablas)</a></li>
<li><a href="horario2.html" title="Horario
(Capas)">Horario (Capas)</a></li </ul>
<li><a href="formularios.html" title="Formulario">Formularios</a>
<ul>
<li><a href="salida.html" title="Formulario -
Submit">Formularios (Haciendo el Submit)</a></li></ul>
<li><a href="imagen_0.html" title="Imagenes Inmenzas">Imagenes
Inmenzas</a <ul>
<li><a href="imagen_1.html" title="Imagenes
Inmenzas">Partiendo en una tabla</a></li>
<li><a href="imagen_2.html" title="Imagenes Inmenzas">Con
Celsspading=0</a></li>
<li><a href="imagen_3.html" title="Imagenes Inmenzas">Con
Border=0</a></li </ul>
<li><a href="javascript.html" title="JavaScript">Javascript</a>
<ul>
<li><a href="j_tabla.html" title="Tabla de Multiplicar y
mas...">Tabla de Multiplicar</a></li>
<li><a href="j.html" title="Mas cosas de
JavaScript">??</a></li>
<li><a href="imagen_3.html" title="Mas">??</a></li </ul>
</ul>
<hr/>
<center<a
href="mailto:ol************@yahoo.es">ol********** **@yahoo.es</a</center>
<hr/>
<form>
¿Cambiar a <select name="Seleccionar" onChange="Cambiar()">
<option selected value="estilo1.css"Estilo 1?
</option>
<option value="estilo2.css"Estilo 2? </option>
<option value="estilo3.css"Estilo 3? </option>
</select>
</form>
<hr/>
</div>
<div id="Contenido">
<form onSubmit = "return generar_tabla(this)">
<table>
<tr>
<td style="width: 10em">Su Nombre:</td>
<td><input type=text name="nombre" size="35" maxlength="50"></td>
</tr>
<tr>
<td>Generar tabla del numero:</td>
<td><input type=text name="multiplicador" size="35" maxlength="5"></td>
<!-- Aqui pondre el mensaje que yo quiera para avisar del error,
recomiendan que ese campo tenga "algo" -->
<td id="error1"> </td>
</tr>
<tr>
<td>Cantidad de filas de la tabla</td>
<td><input type=text name="cantidad" size="35" maxlength="5"></td>
<td id="error2"> </td>
</tr>
<tr>
<td><input type="submit" value="Generar Tabla"</td>
</tr>
</table>
</form>
</div>
</body>
</html>