Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8044 > unrolled thread

Code not working

Started byMclaren Fan <himanshu1495@gmail.com>
First post2011-11-05 08:41 -0700
Last post2011-11-06 19:39 +0000
Articles 16 — 10 participants

Back to article view | Back to comp.lang.javascript


Contents

  Code not working Mclaren Fan <himanshu1495@gmail.com> - 2011-11-05 08:41 -0700
    Re: Code not working williamc <temp4@williamc.com> - 2011-11-05 12:10 -0400
    Re: Code not working Jake Jarvis <pig_in_shoes@yahoo.com> - 2011-11-05 17:19 +0100
    Re: Code not working Luuk <Luuk@invalid.lan> - 2011-11-05 17:15 +0100
      Re: Code not working "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-05 19:56 +0200
        Re: Code not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-05 21:34 +0100
          Re: Code not working "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-05 23:11 +0200
            Re: Code not working Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2011-11-06 01:06 +0100
            Re: Code not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-06 21:11 +0100
              Re: Code not working "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-06 22:59 +0200
                Re: Code not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-07 00:12 +0100
          Re: Code not working Dr J R Stockton <reply1144@merlyn.demon.co.uk> - 2011-11-06 19:53 +0000
            Re: Code not working Mike Duffy <Use_guestbook_page@website.in.sig> - 2011-11-07 02:54 +0000
    Re: Code not working Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-05 23:58 +0000
      Re: Code not working Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-08 21:43 +0100
    Re: Code not working Dr J R Stockton <reply1144@merlyn.demon.co.uk> - 2011-11-06 19:39 +0000

#8044 — Code not working

FromMclaren Fan <himanshu1495@gmail.com>
Date2011-11-05 08:41 -0700
SubjectCode not working
Message-ID<11359e10-c765-4434-ae51-703c99b5d60f@x36g2000prb.googlegroups.com>
<html>
<head>
<title>a</title>
</head>
<body bgColor="white">
<script type="text/javscript">
function toogle() {
if (document.bgColor=='white') {
document.bgColor='red';
}
else if (document.bgColor=='red') {
document.bgColor='blue';
}
else {
document.bgColor='green';
}
}
</script>
Change Color
<input type="button" onClick="toogle()" value="change">
</body>
</html>
Not working the above code should change background color like a
toogler pleasehelp

[toc] | [next] | [standalone]


#8045

Fromwilliamc <temp4@williamc.com>
Date2011-11-05 12:10 -0400
Message-ID<GYGdne8vgpue_SjTnZ2dnUVZ_oidnZ2d@giganews.com>
In reply to#8044
On 11/5/2011 11:41 AM, Mclaren Fan wrote:
> <html>
> <head>
> <title>a</title>
> </head>
> <body bgColor="white">
> <script type="text/javscript">
> function toogle() {
> if (document.bgColor=='white') {
> document.bgColor='red';
> }
> else if (document.bgColor=='red') {
> document.bgColor='blue';
> }
> else {
> document.bgColor='green';
> }
> }
> </script>
> Change Color
> <input type="button" onClick="toogle()" value="change">
> </body>
> </html>
> Not working the above code should change background color like a
> toogler pleasehelp

maybe you have a browser that doesn't support javscript?

-- 

-williamc

[toc] | [prev] | [next] | [standalone]


#8046

FromJake Jarvis <pig_in_shoes@yahoo.com>
Date2011-11-05 17:19 +0100
Message-ID<9hl60eF6h9U1@mid.uni-berlin.de>
In reply to#8044
On 05.11.2011 16:41, Mclaren Fan wrote:
> <html>
> <head>
> <title>a</title>
> </head>
> <body bgColor="white">
> <script type="text/javscript">
                      ^^^^
You have made a typo.

<snip>

-- 
Jake Jarvis

[toc] | [prev] | [next] | [standalone]


#8047

FromLuuk <Luuk@invalid.lan>
Date2011-11-05 17:15 +0100
Message-ID<r14go8-eub.ln1@luuk.invalid.lan>
In reply to#8044
On 05-11-2011 16:41, Mclaren Fan wrote:
> <html>
> <head>
> <title>a</title>
> </head>
> <body bgColor="white">
> <script type="text/javscript">

you are missing an 'a' in 'javascript'


> function toogle() {
> if (document.bgColor=='white') {

this will no be true, because document.bgColor will be '#ffffff' after
the page is loaded, because you set it to 'white'.......

> document.bgColor='red';
> }
> else if (document.bgColor=='red') {
> document.bgColor='blue';
> }
> else {
> document.bgColor='green';
> }
> }
> </script>
> Change Color
> <input type="button" onClick="toogle()" value="change">
> </body>
> </html>
> Not working the above code should change background color like a
> toogler pleasehelp


-- 
Luuk

[toc] | [prev] | [next] | [standalone]


#8048

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2011-11-05 19:56 +0200
Message-ID<j93tcs$jcg$1@dont-email.me>
In reply to#8047
11/5/2011 6:15 PM, Luuk wrote:

>> <script type="text/javscript">
>
> you are missing an 'a' in 'javascript'

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).

>> function toogle() {
>> if (document.bgColor=='white') {
>
> this will no be true, because document.bgColor will be '#ffffff' after
> the page is loaded, because you set it to 'white'.......

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".

>> Not working the above code should change background color like a
>> toogler pleasehelp

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.)

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#8049

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-11-05 21:34 +0100
Message-ID<1996701.i4alEN71Z9@PointedEars.de>
In reply to#8048
Jukka K. Korpela wrote:

> 11/5/2011 6:15 PM, Luuk wrote:
>>> <script type="text/javscript">
>> you are missing an 'a' in 'javascript'
> 
> 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).

No, it illustrates that a markup validator is to be used (before publishing 
content).

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.
 

PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
 -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

[toc] | [prev] | [next] | [standalone]


#8058

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2011-11-05 23:11 +0200
Message-ID<j948qn$vn6$1@dont-email.me>
In reply to#8049
11/5/2011 10:34 PM, Thomas 'PointedEars' Lahn trolled:

> Jukka K. Korpela wrote:
>
>> 11/5/2011 6:15 PM, Luuk wrote:
>>>> <script type="text/javscript">
>>> you are missing an 'a' in 'javascript'
>>
>> 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).
>
> No, it illustrates that a markup validator is to be used (before publishing
> content).

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.

> An omitted `type' attribute may mean that the script is not executed or that
> its content is regarded a syntax error.

In which browser? As usual, you mention browser behavior without 
specifying anything specific.

> Especially when a `language'
> attribute different from "JavaScript" (any letter-case variant) has been
> used before.

No such attribute was used, except in your dreams and in coding style of 
the 1990s.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#8064

FromEric Bednarz <bednarz@fahr-zur-hoelle.org>
Date2011-11-06 01:06 +0100
Message-ID<m2vcqyazcs.fsf@nntp.bednarz.nl>
In reply to#8058
"Jukka K. Korpela" <jkorpela@cs.tut.fi> writes:

> 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.

Please, let’s not split hairs here.

[toc] | [prev] | [next] | [standalone]


#8088

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-11-06 21:11 +0100
Message-ID<2313595.P6UQk0Ptvu@PointedEars.de>
In reply to#8058
Jukka K. Korpela wrote:

> […] Thomas 'PointedEars' Lahn [wrote]:
>> Jukka K. Korpela wrote:
>>> 11/5/2011 6:15 PM, Luuk wrote:
>>>>> <script type="text/javscript">
>>>> you are missing an 'a' in 'javascript'
>>> 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).
>>
>> No, it illustrates that a markup validator is to be used (before
>> publishing content).
> 
> No markup validator reports <script type="text/javscript"> as an error

AISB, you will have to prove your assertions if you want to be taken 
seriously.

> (because it is not a reportable markup error). 

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 
unfeasible.

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">
    <xs:annotation>
      <xs:documentation>
        Media types for ECMAScript implementations, as per [RFC 4329]
      </xs:documentation>
    </xs:annotation>
    <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:restriction>
  </xs:simpleType>  

  …

  <xs:element name="script">
    <xs:annotation>
      <xs:documentation>
        script statements, which may include CDATA sections
      </xs:documentation>
    </xs:annotation>
    <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:simpleType>
          <xs:restriction base="xs:token">
            <xs:enumeration value="defer"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
      <xs:attribute ref="xml:space" fixed="preserve"/>
    </xs:complexType>
  </xs:element>

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.


PointedEars
___________
 [1] <http://www.w3.org/TR/html401/interact/scripts.html#adef-type-SCRIPT>
 [2] <http://dev.w3.org/html5/spec/scripting-1.html#attr-script-type>
 [3] <http://tools.ietf.org/html/rfc2616#section-3.7>
 [4] <http://www.w3.org/TR/html401/types.html#h-6.7>
 [5] <http://dev.w3.org/html5/spec/infrastructure.html#valid-mime-type>
 [6] <http://validator.w3.org/whatsnew.html>, "2008-11-20 — 0.8.4 release"
 [7] <http://dev.w3.org/html5/spec/syntax.html#the-doctype>
 [8] <http://www.w3.org/TR/xhtml1-schema/>
 [9] <http://schneegans.de/sv/>
[10] <http://www.iana.org/assignments/media-types/index.html>
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
 -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

[toc] | [prev] | [next] | [standalone]


#8089

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2011-11-06 22:59 +0200
Message-ID<j96sg0$h28$1@dont-email.me>
In reply to#8088
11/6/2011 10:11 PM, Thomas 'PointedEars' Lahn trolled:

>> No markup validator reports <script type="text/javscript">  as an error
>
> AISB, you will have to prove your assertions if you want to be taken
> seriously.

You made a claim, you prove it. Of course you cannot, hence you babble 
in your trolling style.

>> (because it is not a reportable markup error).
>
> You are wrong.

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 
"theories."

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

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.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#8092

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-11-07 00:12 +0100
Message-ID<20322927.VN2gpG6Qkq@PointedEars.de>
In reply to#8089
Jukka K. Korpela wrote:

> 11/6/2011 10:11 PM, Thomas 'PointedEars' Lahn trolled:
>>> No markup validator reports <script type="text/javscript">  as an error
>> AISB, you will have to prove your assertions if you want to be taken
>> seriously.
> 
> You made a claim, you prove it.

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.

>>> (because it is not a reportable markup error).
>> You are wrong.
> 
> 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. […]

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 
argument.


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

[toc] | [prev] | [next] | [standalone]


#8094

FromDr J R Stockton <reply1144@merlyn.demon.co.uk>
Date2011-11-06 19:53 +0000
Message-ID<2uWCSrIUXutOFwud@invalid.uk.co.demon.merlyn.invalid>
In reply to#8049
In comp.lang.javascript message <1996701.i4alEN71Z9@PointedEars.de>,
Sat, 5 Nov 2011 21:34:47, Thomas 'PointedEars' Lahn <PointedEars@web.de>
posted:

>Jukka K. Korpela wrote:
>
>> 11/5/2011 6:15 PM, Luuk wrote:
>>>> <script type="text/javscript">
>>> you are missing an 'a' in 'javascript'
>>
>> 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).
>
>No, it illustrates that a markup validator is to be used (before publishing
>content).

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
too.

-- 
 (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike 6.05  WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

[toc] | [prev] | [next] | [standalone]


#8097

FromMike Duffy <Use_guestbook_page@website.in.sig>
Date2011-11-07 02:54 +0000
Message-ID<Xns9F95DEE148F17invalidcom@94.75.214.39>
In reply to#8094
Dr J R Stockton <reply1144@merlyn.demon.co.uk> wrote in
news:2uWCSrIUXutOFwud@invalid.uk.co.demon.merlyn.invalid: 

> Outside the Principality at least, the word
> "Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch" should
> work too.

I'm curious, Dr. Stockton. In which field of study do you hold your 
Doctorate?

-- 
http://pages.videotron.ca/duffym/index.htm#

[toc] | [prev] | [next] | [standalone]


#8061

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2011-11-05 23:58 +0000
Message-ID<4eb5cd88$0$28441$a8266bb1@newsreader.readnews.com>
In reply to#8044
On Sat, 05 Nov 2011 08:41:13 -0700, Mclaren Fan wrote:

> Not working the above code should change background color like a toogler
> pleasehelp

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];

http://www.sined.co.uk/tmp/toogle.htm

Rgds

Denis McMahon

[toc] | [prev] | [next] | [standalone]


#8145

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2011-11-08 21:43 +0100
Message-ID<1933274.nKmheAe9J7@PointedEars.de>
In reply to#8061
Denis McMahon wrote:

> Mclaren Fan wrote:
>> Not working the above code should change background color like a toogler
>> pleasehelp
> 
> 1) the content attribute of the script element needs to be a recognised
> script language. I've never heard of javscript!

The `script' element does not have a `content' attribute.  It has a `type' 
attribute, for example.

> How to find the body element:
> 
> var body = document.getElementsByTagName("body")[0];

Because

  var body = document.body;

is too simple, too compatible or too efficient?
 

PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

[toc] | [prev] | [next] | [standalone]


#8093

FromDr J R Stockton <reply1144@merlyn.demon.co.uk>
Date2011-11-06 19:39 +0000
Message-ID<L9D9GqGBKutOFwIu@invalid.uk.co.demon.merlyn.invalid>
In reply to#8044
In comp.lang.javascript message <11359e10-c765-4434-ae51-703c99b5d60f@x3
6g2000prb.googlegroups.com>, Sat, 5 Nov 2011 08:41:13, Mclaren Fan
<himanshu1495@gmail.com> posted:

><html>
><head>
><title>a</title>
></head>
><body bgColor="white">
><script type="text/javscript">
>function toogle() {
>if (document.bgColor=='white') {
>document.bgColor='red';
>}
>else if (document.bgColor=='red') {
>document.bgColor='blue';
>}
>else {
>document.bgColor='green';
>}
>}
></script>
>Change Color
><input type="button" onClick="toogle()" value="change">
></body>
></html>
>Not working the above code should change background color like a
>toogler pleasehelp


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 <http://validator.w3.org/>.

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".

-- 
 (c) John Stockton, nr London UK.  ?@merlyn.demon.co.uk  IE8 FF3 Op12 Sf5 Cr12
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web