473,835 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem applying HTML 4.01 DOM in scripting

Hi All,

I've taken the advice of a few people and managed to cobble together an
HTML 4.01 Strict-compliant document (according to the W3C Validation
Service), but the way I try to pass a TextArea object to a script
function doesn't work.

What's the least amount of change I can make to this to remain
compliant but also correct for execution?

TIA,
Richard

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
// if ((o = o.form) && (o = o.elements) && (o = o['MyTextArea']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<div>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">It em 1</b> <i>Item 2</i></p>
<input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLin es(MyTextArea, 12)" />
<br />
<br />
<input id="MyTextArea " style="width: 420px; height: 122px"
type="text" /></div>
</body>
</html>

Mar 18 '06 #1
29 1812
Richard Lionheart wrote:
, but the way I try to pass a TextArea object to a script
function doesn't work. <input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLin es(MyTextArea, 12)" />
MyTextArea is an underfined variable. You probably want something like:
onclick="GenLin es(this.form.el ements['MyTextArea'], 12);"
<br /> Don't use XHTML style self closing tags in HTML. Their meaning is different.
<input id="MyTextArea " style="width: 420px; height: 122px"
type="text" /></div>


--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Mar 18 '06 #2
VK

Richard Lionheart wrote:
Hi All,

I've taken the advice of a few people and managed to cobble together an
HTML 4.01 Strict-compliant document (according to the W3C Validation
Service), but the way I try to pass a TextArea object to a script
function doesn't work.

What's the least amount of change I can make to this to remain
compliant but also correct for execution?

TIA,
Richard

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
// if ((o = o.form) && (o = o.elements) && (o = o['MyTextArea']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<div>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">It em 1</b> <i>Item 2</i></p>
<input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLin es(MyTextArea, 12)" />
<br />
<br />
<input id="MyTextArea " style="width: 420px; height: 122px"
type="text" /></div>
</body>
</html>


Was it a check for local public? ;-)

This page cannot possibly be a valid HTML of any kind just because it
uses XHTML tag format />

Also input=text accepts *single line text*. For multiline text you use
<textarea>. Also... any way, there is no "minimum change" here - it has
to be completely rewritten. Study the valid variant, do not hesitate to
ask if some changes are not clear:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML Strict 4.01//EN"
"http://www.w3.org/TR/html401/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<style type="text/css">
#red {color:red}
.blue {color:blue}
</style>
<script type="text/javascript">
function GenLines(o, n) {
var aL = [];
for (var i=0; i<=n; i++) {
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
</script>
</head>
<body>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p><b class="blue">It em 1</b> <i>Item 2</i></p>
<form action="">
<fieldset>
<legend>Hello W3C world!</legend>
<input id="Button1" type="button" value="Click for 12 lines"
onClick="GenLin es(this.form.el ements['MyTextArea'],12)">
<br>
<br>
<textarea name="MyTextAre a" cols="20" rows="12"></textarea>
</fieldset>
</form>
</body>
</html>

Mar 18 '06 #3
VK wrote:
This page cannot possibly be a valid HTML of any kind just because it
uses XHTML tag format />


Actually, it can.

<foo /> means the same as <foo>> and thus <foo>&gt; in HTML. So anywhere you
are allowed character data, you can use XHTML style self-closing tags and
be valid. (So <img> and <br>, along with <hr> in some circumstances).

Of course, while it is valid, it doesn't mean what you are trying to say, so
it should be avoided. (You just can't expect the Markup Validator to pick
up on that error).

--
David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Mar 18 '06 #4
Hi David,

Thanks for taking the trouble to respond to my question.
You probably want something like:

onclick="GenLin es(this.form.el ements['MyTextArea'], 12);"

I sure do. But I didn't want my code embedded in <form> tags because
the W3C validator wanted an "action" attribute for <form>.

To get this working, I:
-- switched to "form"
-- removed <br />
-- re-established a conditional around my "for" loop that had been
recommended

This was partially successful. I got "Line 1" in MyTextArea, but not
12 "Line x" entries stacked in TextArea that I had gotten before I
switched to this DOM approach.

I added a debug line before the loop, and that yielded "n = 12"
(confirming that the count was being passed successfully to the
function) instead of "Line 1".

If you can give me another push forward, I might be able to climb this
mountain :-)

Again, thanks in advance.
Richard

******** Revised code ************
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
// aL.push("n = " + n); // DEBUG
if ((o = o.form) && (o = o.elements) && (o = o['MyTextArea']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<form action="FormOut put.txt">
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p>
<b class="blue">It em 1</b> <i>Item 2</i></p>
<p><input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLin es(this.form.el ements['MyTextArea'], 12)"
/></p>
<p>
<input id="MyTextArea " style="width: 420px; height: 122px"
type="text" /></p>
</form>
</body>
</html>

Mar 18 '06 #5
VK

Richard Lionheart wrote:
If you can give me another push forward, I might be able to climb this
mountain :-)


Please see the working and validated example I already posted.

<form action=""> is the regular way to pacify validator (method is
"GET" by default). The most important HTML error made (skipping on
script) is that input=text accept *single line text*. To display
multiline text you have to use <textarea>

Mar 18 '06 #6
Hey VK and David,

You folks are great. I see where all the mistakes are now. I'm going
to clean it up now and post back for just a couple of follow-up
questions if W3Schools et al don't seem to provide relevant guidance.

Thanks to you both.

Regards,
Richard

Mar 18 '06 #7
VK

David Dorward wrote:
VK wrote:
This page cannot possibly be a valid HTML of any kind just because it
uses XHTML tag format />


Actually, it can.


Actually it cannot ;-)

By reading <http://www.w3.org/TR/html401/strict.dtd> (which no one
seems to read but everyone links :-) we see no "/" as valid entity
within <...>

The allowed entities are spelled rather explicetly: tag name itself,
tag attribute name, tag attribute value, event handler name, etc...

"/" character is neither of all of this, so must be treated equally
with say "wrap" attribute or any other unrecognized entity.
The only reason Validator doesn't get upset on it is because it was
intentionally patched to stimulate XHTML usage (in any shall perform
form).

Mar 18 '06 #8
Hey VK, your suggestions work GREAT. Many thanks.
which no one seems to read but everyone links :-)


Hey, nobody sits down and reads the entire dictionary either :-)

But your preceding comment explains why M/S VWD keep closing "<br" with
" />" when I key in a simple ">".

Both of you folks have resuscitated my understanding that ensuring
every tag had closure was an XML requirement, not an HTML issue.

And it was great to find out that including <fieldset> obviated the
need for those <p> tags I had to apply as a kludge to avoid complaints
from the W3C Validator.

I originally had a <textarea> specification but lost it unknowingly
when I accepted someone else's idea of "objectifyi ng" my original code.

QUESTION: What do you think of the protection this other person
recommended around the function. Is it helpful. If I use it,
shouldn't have "else alert" code accompanying it?

Again, thanks to you both for helping me escape my frustration and
enlightening me at the same time.

Best wishes,
Richard

Mar 18 '06 #9
Woops. Here's the clean code for my personal "model comploiant code":

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>An "HTML 4.01 Strict" compliant document</title>
<meta http-equiv="Content-Style-Type" content="text/css" >
<meta http-equiv="content-type"
content="text/html;charset=IS O-8859-1" >
<style type="text/javascript">
#red {color:red}
.blue {color:blue}
</style>

<script type="text/javascript">
function GenLines(o, n)
{
var aL = []; // Array of lines, sans newlines, which will
populate MyTextArea
// when concatenated with newline separators
if ((o = o.form) && (o = o.elements) && (o = o['MyTextArea']))
{
for (var i=1; i<=n; i++)
{
aL.push("Line " + i);
}
o.value = aL.join("\n");
}
}
</script>

</head>
<body>
<p>
... Your HTML content here ...</p>
<p id="red">
DOCTYPEs are "seatbelts" for HTML authors</p>
<p>
<b class="blue">It em 1</b> <i>Item 2</i></p>
<form action="">
<fieldset>
<legend>Hello W3C world!</legend>
<input id="Button1" type="button" value="Click for 12 lines"
onclick="GenLin es(this.form.el ements['MyTextArea'], 12)">
<br><br>
<textarea name="MyTextAre a" cols="20" rows="12"></textarea>
</fieldset>
</form>
</body>
</html>

Mar 18 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
21779
by: Burton Figg | last post by:
My homepage, www.jimpix.co.uk uses transitional XHTML. The whole thing validates except one line: <noscript><img height="1" width="1" alt="" src="http://u0.extreme-dm.com/0.gif?tag=riggott&amp;j=n" /></noscript> I get this error on this page: http://validator.w3.org/check?uri=http://www.jimpix.co.uk
6
9567
by: NoCopy na | last post by:
Using the following example: domiframetest.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>DOM Iframe Test</title>
10
3119
by: Mark McLellan | last post by:
Dear all Following the oft-repeated advice here and ciwas I have made my site nearly 4.01 strict (working on it). There are some items on which I would appreciate your advice: 1. Hidden fields http://www.zoo.co.uk/~mmenterprises/contact.htm I am using FormMail from Matt's Script Archive. The W3C validator objected to the hidden fields unless I put, say, P round them. That gave
4
5255
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
2
2538
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I am really desperate now, because I havent' been able to locate the origin of the problem for a couple of days now.. PROBLEM: the message digest obtained differs each time I execute the code, but works perfectly when applying the "control", that...
6
5586
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an object collection and stanrd using it it starts to fall apart. Clearly there is something about javascript's usage of passing "By ref" that i am not getting. i have had a look on the web and found some examples, but i cant see why my code does not...
34
3885
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
8
2080
by: toby989 | last post by:
Hi All I am completely new to this, but I was wondering if I can apply 2 xslt's subsequently to an xml, via the (client side) scripting method: http://www.w3schools.com/xsl/xsl_client.asp Like maybe: <html>
4
3594
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in the...
0
9808
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9652
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10812
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10523
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10235
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6966
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5638
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3995
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.