473,411 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Document.Write with HTML

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
4 2798
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
> 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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
10
by: Geoff | last post by:
I am using the following statement in a script: If (res == 123) document.write (" Blah Blah"); else document.write (" XYZ"); This of course brings up a new page on my site and prints Blah...
11
by: Tony | last post by:
Is it me, or is document.write just about the most abused js function? Maybe, like goto, js would be better without it? Is there any good reason to use it? Because I'm having a hard time seeing...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
1
by: anupamaavadutha | last post by:
hi all, iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code. <%@ page...
8
by: Mateusz Viste | last post by:
Hi, I am trying make some multimedia files playable from my website. So far, I am able to generate dynamically a new page containing the right <embed> section. However, when I load my script, it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.