Some Early Topics

J

joy99

Dear Group,

I am bit new in this group, so with Java Script.

I was reading some early tutorials on it.

My questions are:

(i) Suppose I write
<script type="text/javascript">
x="My Name"
document.write("<h1>x</h1>);
</script>

would it show the result i.e., the string value of x in header 1?
If not, how can I display the font values to my declared variables?

Is there any good URL to practice/learn on this topic?

(ii) Can I combine CSS with JScript?
If anyone can give me one/two basic examples, a good URL to learn on
my own is obviously better.

(iii) Though Java and Javascript are hugely different but do they have
any similarity in syntax?

Wishing you a happy day ahead,
Best Regards,
Subhabrata.
 
D

David Mark

joy99 said:
Dear Group,

I am bit new in this group, so with Java Script.

Javascript (one word).
I was reading some early tutorials on it.

My questions are:

(i) Suppose I write
<script type="text/javascript">
x="My Name"
document.write("<h1>x</h1>);
</script>

would it show the result i.e., the string value of x in header 1?

No, not even if you fix the syntax error (missing trailing quote).
If not, how can I display the font values to my declared variables?

Do you mean the string value? Like this:-

document.write( said:
Is there any good URL to practice/learn on this topic?

What topic?
(ii) Can I combine CSS with JScript?

Javascript. JScript is the name of Microsoft's Javascript
implementation. What do you mean by combine CSS?
If anyone can give me one/two basic examples, a good URL to learn on
my own is obviously better.

Examples of what?
(iii) Though Java and Javascript are hugely different but do they have
any similarity in syntax?

You got it right that time. :) And there are only superficial
similarities.
 
S

Stevo

joy99 said:
(i) Suppose I write
<script type="text/javascript">
x="My Name"
document.write("<h1>x</h1>);
</script>

would it show the result i.e., the string value of x in header 1?
If not, how can I display the font values to my declared variables?

Why ask the question? It's easier to try it than to find this group and
ask. Two minutes in notepad (or the equivalent simple text editor in
your favorite OS) and drag/drop it onto your favorite browser. If you
drop it onto Firefox, the error console will quickly show you the
trailing quote is missing after </h1>. It's nothing unique to JavaScript
that the code you've written would not use the x variable though. It's
just a letter in a string. You need to break out of the string, access x
and then resume the string:

document.write("<h1>" + x + "</h1>");

You said you were reading some tutorials already? Did you stop at page 4
? This is pretty early-in-the-tutorials kind of stuff.
 
D

David Mark

Stevo said:
Why ask the question? It's easier to try it than to find this group and
ask. Two minutes in notepad (or the equivalent simple text editor in
your favorite OS) and drag/drop it onto your favorite browser. If you
drop it onto Firefox, the error console will quickly show you the
trailing quote is missing after </h1>. It's nothing unique to JavaScript
that the code you've written would not use the x variable though. It's
just a letter in a string. You need to break out of the string, access x
and then resume the string:

document.write("<h1>" + x + "</h1>");

But if it is inline script, you need to escape the slash so the second
string value isn't mistaken for a closing H1 tag.

document.write("<h1>" + x + "<\/h1>");
 
J

joy99

But if it is inline script, you need to escape the slash so the second
string value isn't mistaken for a closing H1 tag.

document.write("<h1>" + x + "<\/h1>");- Hide quoted text -

- Show quoted text -

Thanx for the answer and sorry for missing the " in the end.
May I put one question back-
How to combine CSS and Javascript? Does anyone know any good tutorial/
url for that?
Regs,
Subhabrata.
 
S

Stevo

David said:
But if it is inline script, you need to escape the slash so the second
string value isn't mistaken for a closing H1 tag.

document.write("<h1>" + x + "<\/h1>");

But it *is* a closing H1 tag ;-) No mistaking about it. If it were a
closing script tag it would need escaping. I can't think of a single
environment where not escaping that would be a problem.
 
D

David Mark

Stevo said:
But it *is* a closing H1 tag ;-) No mistaking about it.

No it most assuredly is not a closing H1 tag. It's a string value in an
inline script.
If it were a
closing script tag it would need escaping. I can't think of a single
environment where not escaping that would be a problem.

No need to think about it. Just do it.
 
S

Stevo

David said:
No it most assuredly is not a closing H1 tag. It's a string value in an
inline script.


No need to think about it. Just do it.

Nike should expand their slogan to that :)
 
T

Thomas 'PointedEars' Lahn

kangax said:
Yeah, one of those things that standard and de-facto standard disagree
on.

How did you get the idea that invalid markup would be a de-facto standard?
A million flies can't be wrong?
I've tested the whole slew of browsers—ancient, mobile, desktop,
etc.—and none would close the script tag on discovery of ETAGO.

You need to test more, and refine your tests. The issue is known to occur
I guess the cost of playing safe is not that big here, but it seems that
any implementation that goes against existing de-facto standard is doomed
to "break" half of the web, that's for sure :)

AISB.


PointedEars
 
E

Eric Bednarz

David Mark said:
No it most assuredly is not a closing H1 tag.

In SGMLese, which is what you seem to be worried about, it most
assuredly is (unless you just take issue with the nomenclature),
otherwise there would be no need to hide ETAGO.

minimal example document:

| <!DOCTYPE script PUBLIC "-//W3C//DTD HTML 4.01//EN">
| <script type='text/javascript'>
| document.write("<h1>" + x + "</h1>");
| </script>

parsing:

| -*- mode: compilation; default-directory: "~/Sites/sandbox/html/" -*-
| Compilation started at Sun Feb 21 00:56:29
|
| onsgmls -c /Volumes/Data/Emacs/SGML/catalog -s etago.html
| onsgmls:etago.html:3:33:E: end tag for element "H1" which is not open
^^^^^^^^^^^^^^^^^^^^^^^^

There you go.
 
D

David Mark

Eric said:
In SGMLese, which is what you seem to be worried about, it most
assuredly is (unless you just take issue with the nomenclature),
otherwise there would be no need to hide ETAGO.

But that's my point. It will be _mistaken_ for a "real" closing tag (as
the validation services point out.
minimal example document:

| <!DOCTYPE script PUBLIC "-//W3C//DTD HTML 4.01//EN">
| <script type='text/javascript'>
| document.write("<h1>" + x + "</h1>");
| </script>

parsing:

| -*- mode: compilation; default-directory: "~/Sites/sandbox/html/" -*-
| Compilation started at Sun Feb 21 00:56:29
|
| onsgmls -c /Volumes/Data/Emacs/SGML/catalog -s etago.html
| onsgmls:etago.html:3:33:E: end tag for element "H1" which is not open
^^^^^^^^^^^^^^^^^^^^^^^^

There you go.

That's what I was saying. It's no good. Even if (most) browsers will
deal with it, I don't like assuming things about browsers and I like to
keep the validation clean so the more important issues are not obscured.
 
T

Thomas 'PointedEars' Lahn

kangax said:
The same way anything else would be considered a de-facto standard.

Then you are mistaken, because a de facto standard is something that is not
(yet) standardized, although regarded so common *and useful* that it is
widely accepted by the public, in particular by the professional community
that it concerns. ("De facto" being Latin for "concerning the fact" or "in
practice".) A synonym is "best current practice" (BCP).

But invalid markup does _not_ appear to be widely accepted, nor does it
appear to be considered best current practice. In fact, there is the
strong recommendation to use Valid markup even though there is built-in
error correction (because while that feature has some informal
recommendations regarding it, there are no must-haves, and therefore it
cannot be relied on).

Do we not see this confirmed every time someone reports problems with a Web
site using invalid markup, and is being told by several rather knowledgable
people to fix their markup first as the problem is likely going to go away
then?

You have evaded that part of the question as well. A great number of
amateurs misusing the feature of built-in error correction, most of the
time without knowing it, does not make their doing any more a de facto
standard than any other of their mistakes.
<script>...</script> is exactly what I've been testing. What more is
there to test if the purpose was to check if SCRIPT content is parsed
properly?

The SCRIPT element with a `type' attribute, and perhaps "nested" SCRIPT
elements.
And which other occasions are you talking about? I haven't seen a client
that respects HTML 4.01 in this regard and closes SCRIPT element on
first occurrence of "</". Have you?

I am sure that the W3C Validator does, IOW not fixing this error makes
further validation of the document using this tool next to impossible.

I do not remember which browsers did this, but there must have been at
least one popular one among them or it would not have become such an issue
in the first place. Probably the list would include W3C Amaya. Lynx,
which is sometimes used by server administrators and as input for
screenreaders, is at least known to report invalid markup visibly (in the
status line), which would not look too good. Very likely further
information can be found in the archives in postings containing the term
"ETAGO" or "End Tag Open delimiter".

By the way, that reminds me of a similar misconception I had found on your
Web site that I did not find time to mail you about yet (so I am doing it
here and now, lest I forget again): You stated there something along the
lines that it would not matter that in XHTML the content of `script'
elements was not, where necessary, properly escaped or declared CDATA,
because the Content-Type `text/html' would not trigger an X(HT)ML parser
anyway. However, first of all you cannot know for sure which parser is
being used, and second it matters for the W3C Validator and any other
markup validator because they MUST NOT care for the Content-Type of the
markup resource with regard to syntax except for the `charset' parameter.
IOW, the markup is still _not_ Valid then. So by _not_ using Valid markup
there, you are shooting yourself in the foot there, too.


HTH

PointedEars
 
J

John G Harris

How did you get the idea that invalid markup would be a de-facto standard?
A million flies can't be wrong?


You need to test more, and refine your tests. The issue is known to occur
with "<script ...>...</script>" in particular, but it has been observed on
other occasions as well.
<snip>

Here's what the HTML 4.01 standard says in section B.3.2 :

When script or style data is the content of an element (SCRIPT and
STYLE), the data begins immediately after the element start tag and
ends at the first ETAGO ("</") delimiter followed by a name start
character ([a-zA-Z]); note that this may not be the element's end
tag.
Authors should therefore escape "</" within the content. Escape
mechanisms are specific to each scripting or style sheet language.

so 'other occasions' should exist.

John
 
E

Eric Bednarz

Richard Cornford said:
It is interesting to note what SGML (ISO 8879) has to say on the
subject, i.e:-

| B.13.1.1 Character Data (PCDATA, CDATA, and RCDATA)
| ...
| If an element contains declared character data, it cannot contain
| anything else. The markup parser scans it only to locate an etago
| or net; other markup is ignored. #Only the correct end-tag (or that
| of an element in which this element is nested) will be recognised.
| ...

That sounds nice, but is in conflict with clause 7.6, which states:

| The content of an element declared to be character data or replaceable
| character data is terminated only by an ETAGO delimiter-in-context
| (which need not open a valid end-tag) or a valid NET.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(where the context of ‘-in-context’ is a name start character, or GRPO
if CONCUR in the SGML declaration is set to YES followed by a number)

This is also how it is implemented in (o)nsgmls and why CDATA is
widely considered BrokenAsDesigned.
 
J

joy99

That sounds nice, but is in conflict with clause 7.6, which states:

| The content of an element declared to be character data or replaceable
| character data is terminated only by an ETAGO delimiter-in-context
| (which need not open a valid end-tag) or a valid NET.
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(where the context of ‘-in-context’ is a name start character, or GRPO
if CONCUR in the SGML declaration is set to YES followed by a number)

This is also how it is implemented in (o)nsgmls and why CDATA is
widely considered BrokenAsDesigned.

Dear Group,

Thank you all for kindly taking your valuable time to guide a new
learner.

Wishing you all A Happy Day Ahead,
Best Regs,
Subhabrata.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,729
Latest member
ScarlettJe

Latest Threads

Top