Code not working

Discussion in 'Javascript' started by Mclaren Fan, Nov 5, 2011.

  1. Mclaren Fan

    Mclaren Fan Guest

    <body bgColor="white">
    <script type="text/javscript">
    function toogle() {
    if (document.bgColor=='white') {
    else if (document.bgColor=='red') {
    else {
    Change Color
    <input type="button" onClick="toogle()" value="change">
    Not working the above code should change background color like a
    toogler pleasehelp
    Mclaren Fan, Nov 5, 2011
    1. Advertisements

  2. Mclaren Fan

    Luuk Guest

    you are missing an 'a' in 'javascript'

    this will no be true, because document.bgColor will be '#ffffff' after
    the page is loaded, because you set it to 'white'.......
    Luuk, Nov 5, 2011
    1. Advertisements

  3. This illustrates why it is better to write just <script>, unless company
    police forces you to conform to formal specs that make the type
    attribute required (for no good reason).
    This depends on the browser. That's why it is better to store the
    current state encoded in a known way, rather than rely on what the
    browser gets out of an attribute like bgColor="white".

    I have no idea of what "toogle" means. But "toggle" means switching
    between _two_ states. This might be important to the OP who appears to
    have some homework on an introductory course on fundamentals of elements
    of basics of JavaScript programming (taught the wrong way as usual and
    probably carrying a hyperbolic name). (People who have serious problems
    usually post a URL.)
    Jukka K. Korpela, Nov 5, 2011
  4. No, it illustrates that a markup validator is to be used (before publishing

    An omitted `type' attribute may mean that the script is not executed or that
    its content is regarded a syntax error. Especially when a `language'
    attribute different from "JavaScript" (any letter-case variant) has been
    used before.

    Thomas 'PointedEars' Lahn, Nov 5, 2011
  5. 11/5/2011 10:34 PM, Thomas 'PointedEars' Lahn trolled:
    No markup validator reports <script type="text/javscript"> as an error
    (because it is not a reportable markup error). A novice might get this
    wrong, but you pretend to be an expert.
    In which browser? As usual, you mention browser behavior without
    specifying anything specific.
    No such attribute was used, except in your dreams and in coding style of
    the 1990s.
    Jukka K. Korpela, Nov 5, 2011
  6. 1) the content attribute of the script element needs to be a recognised
    script language. I've never heard of javscript!

    2) is bgColor a settable property of the javascript document object?

    hint: [element].style.backgroundColor = value;

    How to find the body element:

    var body = document.getElementsByTagName("body")[0];


    Denis McMahon
    Denis McMahon, Nov 5, 2011
  7. Mclaren Fan

    Eric Bednarz Guest

    Please, let’s not split hairs here.
    Eric Bednarz, Nov 6, 2011
  8. In comp.lang.javascript message <[email protected]>, Sat, 5 Nov 2011 08:41:13, Mclaren Fan

    Your WORST error is that you were not testing in a browser with error
    console displayed (or if you did, not reporting what was reported).

    Other errors, not affecting the results of your test, can be found with
    W3's downloadable TIDY, and with <>.

    There is often something to be said for using non-words as identifiers;
    but neither "toogler" nor "pleasehelp" are English words - to say
    nothing of "Color".
    Dr J R Stockton, Nov 6, 2011
  9. In comp.lang.javascript message <>,
    Not very well. Using Opera context-menu Validate, W3 appears to accept
    '<script type="text/javscript">'.

    For the OP:

    When a function shows no sign of functioning, the first thing to do is
    to make sure that it is being read, for example by inserting
    ... // ... is a literal
    and checking that the error console does not get a report of that. Then
    change ... to ying-tong-iddle-I-po which almost certainly will show an
    error on execution.

    If an entire script shows no sign of working, insert a magic word at its
    beginning, and check the console.

    Outside the Principality at least, the word
    "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch" should work
    Dr J R Stockton, Nov 6, 2011
  10. AISB, you will have to prove your assertions if you want to be taken
    You are wrong.

    The HTML 4.01 and 5 (Draft) Specifications state that the value of the
    `type' attribute of the `script' element must be a "(valid MIME/)content
    type" [1,2] (from here: MIME type). A valid MIME type should not only
    conform to syntactical requirements for MIME types (although the HTML5 draft
    states that this suffices [2]), but it should also be registered with IANA
    [10], which limits the acceptable attribute values.

    The set of MIME types that are reasonable to use here is further limited by
    the element type. A markup validator could (indeed, it should) report at
    least a warning for a non-registered MIME type such as "text/javscript", as
    their use is "discouraged" by RFC 2616 [3], which HTML 4.01 through RFCs
    2045 and 2046 [4], and HTML5 directly [5], refer to.

    Since the W3C Markup Validator already does experimental markup validation
    that is not based on a DTD, for HTML5 [6] (because there is no HTML5 DTD
    [7]), it is not too much of a stretch to expect it to report that as an
    error or at least issue a warning. Unfortunately, it does neither for now;
    but other validators might do that already, and the W3C Markup Validator
    could do that in the future. The set of registered MIME types, especially
    the set of programming languages that can be used for client-side scripting
    from within (X)HTML (or SVG), does not change so often to make it

    In addition to hard-coded validation, it is also possible to validate XHTML,
    the XHTML syntax of HTML5 or any other XML-based document against an XML
    Schema Definition (cf. [8,9]). XML Schema allows the definition of
    restrictions for attribute values so that `type="text/javscript"' would not
    pass validation. For a simple example ([8] slightly adapted):


    <xs:simpleType name="ScriptType">
    Media types for ECMAScript implementations, as per [RFC 4329]
    <xs:restriction base="xs:string">
    <xsd:enumeration value="application/ecmascript"/>
    <xsd:enumeration value="application/javascript"/>
    <xsd:enumeration value="text/ecmascript"/>
    <xsd:enumeration value="text/javascript"/>


    <xs:element name="script">
    script statements, which may include CDATA sections
    <xs:complexType mixed="true">
    <xs:attribute name="id" type="xs:ID"/>
    <xs:attribute name="charset" type="Charset"/>
    <xs:attribute name="type" use="required" type="ScriptType"/>
    <xs:attribute name="src" type="URI"/>
    <xs:attribute name="defer">
    <xs:restriction base="xs:token">
    <xs:enumeration value="defer"/>
    <xs:attribute ref="xml:space" fixed="preserve"/>

    For maximum flexibility, such a Schema or an equivalent list of acceptable
    MIME types could be generated from [10] or resources such as /etc/mime.types
    dynamically, or updated regularly.

    So in fact there are various ways, including those mentioned, that allow
    such errors in attribute values to be flagged upon markup validation.

    [1] <>
    [2] <>
    [3] <>
    [4] <>
    [5] <>
    [6] <>, "2008-11-20 — 0.8.4 release"
    [7] <>
    [8] <>
    [9] <>
    [10] <>
    Thomas 'PointedEars' Lahn, Nov 6, 2011
  11. 11/6/2011 10:11 PM, Thomas 'PointedEars' Lahn trolled:
    You made a claim, you prove it. Of course you cannot, hence you babble
    in your trolling style.
    You could prove me wrong if you cited a specification or mentioned a
    single validator, or even a linter called a "validator", if that were
    possible. But it isn't, so you keep trolling with irrelevant remarks and
    Are you saying that you could, in theory, create some software you call
    as validator and that would give the report you referred to? But you
    just couldn't "bother". I'm not surprised.

    So instead of throwing some list of irrelevant URLs at us, can you
    specify any "validator" that gives the report you referred to, even
    under a most liberal interpretation of "validator"?

    Consider your trolling to have been exposed.
    Jukka K. Korpela, Nov 6, 2011
  12. I have made no claim, you did. The claim you made is quoted (by you) above.
    You will still have to prove that, or retract the claim, if you want to be
    taken seriously.
    No, I have already proven you wrong, pointing out what is already possible
    to make this a reportable markup error. Possibilities that you were either
    not aware of or purposely neglected to consider because that fit your

    Thomas 'PointedEars' Lahn, Nov 6, 2011
  13. Mclaren Fan

    Mike Duffy Guest

    I'm curious, Dr. Stockton. In which field of study do you hold your
    Mike Duffy, Nov 7, 2011
  14. The `script' element does not have a `content' attribute. It has a `type'
    attribute, for example.

    var body = document.body;

    is too simple, too compatible or too efficient?

    Thomas 'PointedEars' Lahn, Nov 8, 2011
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.