473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

getElementByID

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.optio ns[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>
Nov 25 '06 #1
6 2095

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.optio ns[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

Nov 25 '06 #2
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">&nbsp;</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">&nbsp;</td>
</tr>
<tr>
<td><input type="submit" value="Generar Tabla"</td>
</tr>
</table>
</form>
</div>
</body>
</html>
Nov 25 '06 #3
David Golightly wrote:
<snip>
Also, what's going on with your HTML? Where's your
"body" tag? Where's your "html" tag?
<snip>

In HTML the opening and closing HTML and BODY tags are optional (and so
may be omitted from a valid HTML document).
... . You really need to have a
solid HTML foundation before starting JavaScript.
Javascript is not restricted only to the task of scripting web browsers.
It would be a good idea to understand HTML prior to attempting to script
a web browser's HTML DOM, but someone scripting WSH, PhotoShop or any
application that exposes an object model that can be scripted with
javascript has no reason to understand HTML first.

Richard.
Nov 26 '06 #4

Richard Cornford wrote:
David Golightly wrote:
... . You really need to have a
solid HTML foundation before starting JavaScript.

Javascript is not restricted only to the task of scripting web browsers.
It would be a good idea to understand HTML prior to attempting to script
a web browser's HTML DOM, but someone scripting WSH, PhotoShop or any
application that exposes an object model that can be scripted with
javascript has no reason to understand HTML first.
True, ECMAScript has been implemented for a variety of purposes,
contexts and platforms besides client-side HTML scripting, and I
could've qualified it, but given the OP's context and intentions
(clearly client-side HTML), why bother? Anyone interested in other
contexts already knows about them, or will find out easily enough.
What's the purpose in pointing out this trivial omission?

Nov 26 '06 #5
David Golightly wrote:
Richard Cornford wrote:
>David Golightly wrote:
... . You really need to have a
solid HTML foundation before starting JavaScript.

Javascript is not restricted only to the task of scripting web
browsers. It would be a good idea to understand HTML prior to
attempting to script a web browser's HTML DOM, but someone scripting
WSH, PhotoShop or any application that exposes an object model that
can be scripted with javascript has no reason to understand HTML
first.

True, ECMAScript has been implemented for a variety of purposes,
contexts and platforms besides client-side HTML scripting,
And JavaScript(tm) and JScript have both been server-side languages
pretty much form their inception (though server-side scripting without
first understanding HTML is not such a good idea either).
and I could've qualified it,
Rather asserted the correct subject; browser scripting specifically as
opposed to javascript in general.
but given the OP's context and intentions
(clearly client-side HTML), why bother?
So as not to inhibit the OP's appreciation of the distinction between
javascript (a general purpose scripting language) and the browser's
object model (the thing that is scripted in the web browser context).
Anyone interested in other contexts already knows
about them, or will find out easily enough.
What's the purpose in pointing out this trivial omission?
To identify the truth in a statement that was false (there is no "need"
to have a solid foundation in HTML before learning a general purpose
scripting language, while there may be a need for it prior to scripting
an HTML related object model). And to avoid the blurring of the
distinction between the language and the object morel that already has
people, for example, speaking of bugs in Safari 1.3's "javascript
engine" when no javascript bugs have been identified in Safari 1.3, just
lots of DOM bugs.

Richard.
Nov 26 '06 #6
In comp.lang.javascript message <ek**********@cormoran.emeteo.local>,
Sat, 25 Nov 2006 22:41:04, Winston <Cl*****@yahoo.eswrote:

><script languaje="JavaScript">
language
>
function verifica(numero, cantidad) {
var sms = "Debe Ingresar un entero";
if (isNaN(numero)) {
document.getElementById("error1").innerHTML = "Debe
Ingresar un entero";
Don't let your posting agent line-wrap code. Posted code should be
directly executable. Your "entero" I think means "integer; isNaN does
not test for integer, but allows -2.96e+25 and Infinity.
return false;
}
if (isNaN(cantidad)) {
document.getElementById("error2").innerHTML = "Debe
Ingresar un entero";
return false;
}
else
Not needed?
return true;
}
cantidad = parseInt(cantidad)
Try cantidad = "08".
W3's free checker TIDY, via sourceforge, gives many warnings;
http://validator.w3.org/ will probably do so too. To be sure of not
wasting time, don't post pages with invalid HTML here.

It's a good idea to read the newsgroup and its old FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
12
by: lawrence | last post by:
The following function correctly makes everything invisible but then fails to turn the one chosen DIV back to visible. I imagine I'm getting the syntax of the variable wrong? I've tried this with...
4
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) {...
7
by: PaulB | last post by:
Good Morning everybody, I'm trying to adapt a tutorial script that will handle the behaviour of an "Expanding/Contracting" site-navigation menu. The code that seems to handle the expansion and...
3
by: davidkarlsson74 | last post by:
Error: document.getElementById("folderMenu").cells has no properties File: http://www.volkswagen.se/tillbehor/js/foldermenu.js Rad: 49 The function activates different DIV:s, but doesn't seem to...
1
by: Andre Ranieri | last post by:
Hello, I'm trying to set up an ASP.NET 2.0 form where the user enters values in WebControls.TextBoxes for amount owing, interest and late fees and a JavaScript function totals the three values...
4
by: dr1ft3r | last post by:
Hey guys, I'm building a site for a landscaping business down the street and can't seem to get part of the code functioning correctly. The code fails on line 68 where I make a reference to an...
13
by: RommelTJ | last post by:
Hi, My website (http://www.justiceinmexico.org/indextest.php) looks good in Firefox, but horrible in IE, and I think it's because of an error in the javascript of a free web ticker I got off the...
5
by: jhappeal | last post by:
I do not know Javascript that well so I might be going about this the wrong way. Any help would be appreciated. This function attempts to hide the options inside of the optgroup tag of the second...
1
by: vikD | last post by:
Hello, I'm really bad at javascript but I managed to get the code below to work in IE but firefox gives this error... Error: document.getElementById.formall is undefined Basically use the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.