getElementByID

Discussion in 'Javascript' started by Winston, Nov 25, 2006.

  1. Winston

    Winston Guest

    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.options[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>
    Winston, Nov 25, 2006
    #1
    1. Advertising

  2. Winston

    Winston Guest

    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.options[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.options[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:eek:"></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>
    Winston, Nov 25, 2006
    #2
    1. Advertising

  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.
    Richard Cornford, Nov 26, 2006
    #3
  4. In comp.lang.javascript message <ekad9h$of9$>,
    Sat, 25 Nov 2006 22:41:04, Winston <> wrote:


    ><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.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Nov 26, 2006
    #4
  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.
    Richard Cornford, Nov 26, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gilles T.
    Replies:
    8
    Views:
    2,084
    Alessandro Zifiglio
    Jan 5, 2004
  2. jm
    Replies:
    1
    Views:
    833
  3. Paul
    Replies:
    8
    Views:
    3,296
  4. Franck
    Replies:
    3
    Views:
    2,387
    Eliyahu Goldin
    Aug 25, 2005
  5. Ferret Face
    Replies:
    3
    Views:
    29,979
    Ferret Face
    Oct 4, 2005
Loading...

Share This Page