By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,385 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,385 IT Pros & Developers. It's quick & easy.

Document.Write with HTML

P: n/a
I generate a SELECT list dynamically by taking items from a table. I
have DOCUMENT.WRITE statements that write a combination of literals and
variables including < and > characters. The HTML seems to work all
right but validators show errors of having a closing > without an
opening <. Even though these are in DOCUMENT.WRITE statements within
quotes they are still flagged as errors.

Is there any way around this. I have tried HTML entities but they cause
problems. They seem to be substituted at the wrong time causing errors.

The page is http://www.dcs-chico.com/~denmarks/amtrak.html

BTW: I've been told that the ID statements are incorrect and I should
use CLASS. ID seems to work. If I should use CLASS could somebody show
me exactly what to change.

I was a mainframe programmer all of my life and javascript is new to
me. I don't care at this time if there is a better way to do the page.
It is for fun and I just want it to be correct.

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
you need to enclose your <script> tags in a CDATA element.
http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.8

Jul 20 '05 #2

P: n/a
> I generate a SELECT list dynamically by taking items from a table. I
have DOCUMENT.WRITE statements that write a combination of literals and
variables including < and > characters. The HTML seems to work all
right but validators show errors of having a closing > without an
opening <. Even though these are in DOCUMENT.WRITE statements within
quotes they are still flagged as errors.
Think of it from an HTML validator's point of view. You have opened a
<script> element which is stuffed full of non-HTML that it cannot interpret
as anything but a stream of characters. It is searching out the closing
HTML tag. When it comes across </ in the script it recognises a closing tag
and then is baffled to find that it isn't a </script> and so complains.
What you do is to escape the / with a backslash so you get e.g.
"....<\/option>..." in the document.write statements. This keeps the HTML
validators happy and the JavaScript interpreter is happy too.
BTW: I've been told that the ID statements are incorrect and I should
use CLASS. ID seems to work. If I should use CLASS could somebody show
me exactly what to change.
If you change e.g. id="red" to class="red" and in your style section change
#red to .red you should be ok. The thing is that an id is supposed to be
unique within the document. It identifies a particular instance.

Note that you really should get into the habit of delimiting the tags with
quotes i.e. id="red" not id=red (in the script you might need to escape the
double quotes with a backslash if you use double quotes for the string). If
they weren't in scripts the validators would probably pick you up on it.
I was a mainframe programmer all of my life and javascript is new to
me. I don't care at this time if there is a better way to do the page.
It is for fun and I just want it to be correct.


Yes you have to start somewhere though it is better to start with good
habits if you can. For example if you decide to change the colour scheme
you might suddenly realise that having classes called "red", "green" and
"blue" no longer seem quite such a good idea!
Jul 20 '05 #3

P: n/a
On Mon, 1 Dec 2003 09:14:21 -0000, "Graham J" <me@privacy.net> wrote:
Note that you really should get into the habit of delimiting the tags with
quotes i.e. id="red" not id=red (in the script you might need to escape the
double quotes with a backslash if you use double quotes for the string). If
they weren't in scripts the validators would probably pick you up on it.
You mean attribute values rather than tags. (Tags are delimited by < and). The delimiting quotes are not required in all circumstances, and I

usually don't bother if the attribute value consists only of letters.
The validators won't complain, because that is valid SGML.

Some people do recommend always using the quotes, even when they are not
required, on the grounds that you might change something and forget to
add the quotes. But that's a judgement call.

--
Stephen Poley
Jul 20 '05 #4

P: n/a
> You mean attribute values rather than tags.

Oopsy! I'd spotted that having just talked about replacing id with class
I'd then used id in the example but missed that I'd written tags by mistake!
The delimiting quotes are not required in all circumstances, and I
usually don't bother if the attribute value consists only of letters.
The validators won't complain, because that is valid SGML.
Yes, what I was trying (and failing) to say was that not having quotes when
you are supposed to have them is another thing some browsers might let you
get away with only for validators to pull you up.
Some people do recommend always using the quotes, even when they are not
required, on the grounds that you might change something and forget to
add the quotes. But that's a judgement call.


IMHO better to make a habit of using the quotes first and then learning
where you can drop them but as you say like several other things web page
related it is down to personal taste. As I say I was really responding in
the context of a situation where browsers allow things to happen but
validators don't and showing another area where it could happen.

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.