Why does textarea.value= not work

S

Sandy Tipper

I have never had a textarea content change, in any browser.
On several different projects.
With javascript enabled (other stuff works.)
I have read lots, and everyone says it should work.
Can anyone tell my what's wrong with the following code?
(I was trying to create a simple demo example.
The alerts are there just to help find out where it fails.
The onClick isn't even getting executed, even though
I get it to work elsewhere.)
------ textarea.htm ---------
<html>
<head>
<script type="text/javascript">
<--
function fillit(obj) {
alert('fillit called');
var x = obj.form.bigbox;
alert('The big box had: ' + x.value);
x.value = 'Some new text';
alert('The big box should have some new text in it.');
return false;
}
//-->
</script>
</head>
<body>
<form id="myform" name="myform" action="textarea.htm" method="post">
<textarea id="bigbox" name="bigbox" rows="5" cols="25">Original
text</textarea>
<input type="submit" id="doit" name="doit" value="Change the text"
onClick="return fillit(this);">
</form>
</body>
</html>
 
L

Lee

Sandy Tipper said:
I have never had a textarea content change, in any browser.
On several different projects.
With javascript enabled (other stuff works.)
I have read lots, and everyone says it should work.
Can anyone tell my what's wrong with the following code?
(I was trying to create a simple demo example.
The alerts are there just to help find out where it fails.
The onClick isn't even getting executed, even though
I get it to work elsewhere.)
------ textarea.htm ---------
<html>
<head>
<script type="text/javascript">
<--
function fillit(obj) {
alert('fillit called');
var x = obj.form.bigbox;
alert('The big box had: ' + x.value);
x.value = 'Some new text';
alert('The big box should have some new text in it.');
return false;
}
//-->
</script>
</head>
<body>
<form id="myform" name="myform" action="textarea.htm" method="post">
<textarea id="bigbox" name="bigbox" rows="5" cols="25">Original
text</textarea>
<input type="submit" id="doit" name="doit" value="Change the text"
onClick="return fillit(this);">
</form>
</body>
</html>

Don't use in input of type "submit" unless you're submitting
the form, and don't use SGML comments around script:

<html>
<head>
<script type="text/javascript">
function fillit(obj) {
alert('fillit called');
var x = obj.form.bigbox;
alert('The big box had: ' + x.value);
x.value = 'Some new text';
alert('The big box should have some new text in it.');
return false;
}
</script>
</head>
<body>
<form id="myform" name="myform" action="textarea.htm" method="post">
<textarea id="bigbox" name="bigbox" rows="5" cols="25">Original
text</textarea>
<input type="button" id="doit" name="doit" value="Change the text"
onClick="return fillit(this);">
</form>
</body>
</html>


--
 
T

Thomas 'PointedEars' Lahn

Sandy said:
<script type="text/javascript">
<--
^^^
There is a syntax error; `<' and `--' are operators. If you had avoided the
nonsensical attempt of pseudo-commenting out `script' element content with
`<!-- ... //-->' in the first place, you would not have fallen victim to
this error. That said, simple debugging would have revealed it:

http://jibbering.com/faq/

Markup validation will reveal more problems with your code:

http://validator.w3.org/


PointedEars
 
S

Sandy Tipper

Thomas 'PointedEars' Lahn said:
^^^
There is a syntax error; `<' and `--' are operators. If you had avoided
the
nonsensical attempt of pseudo-commenting out `script' element content with
`<!-- ... //-->' in the first place, you would not have fallen victim to
this error. That said, simple debugging would have revealed it:
http://jibbering.com/faq/
Markup validation will reveal more problems with your code:
http://validator.w3.org/

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

No need to be sarcastic. Especially when you're on thin ice.
The comments vare recommended practice to prevent misunderstanding
by old browsers who don't recognoze the <script> tag. See:
http://www.w3schools.com/html/html_scripts.asp
HJowever, I know there are problems with the code,
that;s why I asked for help.
My debugger doidn't see anthing wrong.with the generated
html page, but I didn't know to use the java cnsole.
So now I know something is wrong, but don't know what.
(I used a "button" instead of "submit", not difference.
 
L

Lasse Reichstein Nielsen

Sandy Tipper said:
I have never had a textarea content change, in any browser.
On several different projects.
With javascript enabled (other stuff works.)
I have read lots, and everyone says it should work.
Can anyone tell my what's wrong with the following code?

How does it fail for you? Does nothing happen? Does the browser give
any error messages? (You do check for browser error messages, right?
:)
(I was trying to create a simple demo example.
The alerts are there just to help find out where it fails.
The onClick isn't even getting executed, even though
I get it to work elsewhere.)
------ textarea.htm ---------
<html>
<head>
<script type="text/javascript">
<--

Bug is here: You wrote "<--" where you probably meant to write "<!--".
You should just omit it totally. It does no good.

This suggests to me that your browser will give an error when the page
is loaded (syntax error on this line) and it will also give an error
when the submit button is clicked ("fillit" is undefined). Then the form
is submitted.
function fillit(obj) {
alert('fillit called');
var x = obj.form.bigbox;

Should work. I prefer "obj.form.elements['bigbox']", but that's pure
pedantry.
alert('The big box had: ' + x.value);
x.value = 'Some new text';
alert('The big box should have some new text in it.');
return false; .....
<input type="submit" id="doit" name="doit" value="Change the text"
onClick="return fillit(this);">

/L
 
L

Lasse Reichstein Nielsen

Sandy Tipper said:
No need to be sarcastic. Especially when you're on thin ice.
The comments vare recommended practice to prevent misunderstanding
by old browsers who don't recognoze the <script> tag. See:
http://www.w3schools.com/html/html_scripts.asp

He is, however, correct in this case.

From the referenced page:
---
A browser that does not recognize the <script> tag at all, will
display the <script> tag's content as text on the page. To prevent
the browser from doing this, you should hide the script in comment
tags. An old browser (that does not recognize the <script> tag) will
ignore the comment and it will not write the tag's content on the
page, while a new browser will understand that the script should be
executed, even if it is surrounded by comment tags.
---

The last such browser was created around 1996. There are no currently
used browsers that don't understand HTML 3.2 (where the script element
was introduced). If there were, most of the current web would be
unusable for them, and there are plenty of free modern browsers to
use instead.

Using "<!--" and "-->" around script content is, at best, harmless,
but I don't advocate adding anything to a page without understanding
*why* it's there. I.e., what problem it is there to solve. In this
case there is no problem.

If you ever add such HTML comments to an XHTML page, though, you will
actually comment out the entire script. If one doesn't know why the
magic incantation is added, one will probably also not know when not
to use it, which is why its use is generally discouraged.
HJowever, I know there are problems with the code,
that;s why I asked for help.
My debugger doidn't see anthing wrong.with the generated
html page, but I didn't know to use the java cnsole.

JavaScript console, probably (if you are using Firefox).
So now I know something is wrong, but don't know what.
(I used a "button" instead of "submit", not difference.

/L
 
S

Sandy Tipper

Lasse Reichstein Nielsen said:
Sandy Tipper said:
I have never had a textarea content change, in any browser.
On several different projects.
With javascript enabled (other stuff works.)
I have read lots, and everyone says it should work.
Can anyone tell my what's wrong with the following code?

How does it fail for you? Does nothing happen? Does the browser give
any error messages? (You do check for browser error messages, right?
:)
(I was trying to create a simple demo example.
The alerts are there just to help find out where it fails.
The onClick isn't even getting executed, even though
I get it to work elsewhere.)
------ textarea.htm ---------
<html>
<head>
<script type="text/javascript">
<--

Bug is here: You wrote "<--" where you probably meant to write "<!--".
You should just omit it totally. It does no good.

This suggests to me that your browser will give an error when the page
is loaded (syntax error on this line) and it will also give an error
when the submit button is clicked ("fillit" is undefined). Then the form
is submitted.
function fillit(obj) {
alert('fillit called');
var x = obj.form.bigbox;

Should work. I prefer "obj.form.elements['bigbox']", but that's pure
pedantry.
alert('The big box had: ' + x.value);
x.value = 'Some new text';
alert('The big box should have some new text in it.');
return false; ....
<input type="submit" id="doit" name="doit" value="Change the text"
onClick="return fillit(this);">

/L
--
Lasse Reichstein Nielsen - (e-mail address removed)
DHTML Death Colors:
<URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Thanks! I caught the missing !, which was not absent i n the longer code,
but the javasript console helped me find the problems.
I had been relying on html output error checking, which missed
javascript errors.
 
T

Thomas 'PointedEars' Lahn

Lasse said:
Sandy Tipper said:
No need to be sarcastic. Especially when you're on thin ice.
The comments vare recommended practice to prevent misunderstanding
by old browsers who don't recognoze the <script> tag. See:
http://www.w3schools.com/html/html_scripts.asp

He is, however, correct in this case.

From the referenced page:
---
A browser that does not recognize the <script> tag at all, will
display the <script> tag's content as text on the page. To prevent
the browser from doing this, you should hide the script in comment
tags. An old browser (that does not recognize the <script> tag) will
ignore the comment and it will not write the tag's content on the
page, while a new browser will understand that the script should be
executed, even if it is surrounded by comment tags.
---

The last such browser was created around 1996. There are no currently
used browsers that don't understand HTML 3.2 (where the script element
was introduced). If there were, most of the current web would be
unusable for them, and there are plenty of free modern browsers to
use instead. [...]

There are several other good arguments to make: As for the HEAD element in
HTML 2.0, user agents that display text content within it are FUBAR. And as
for HTML 2.0, it was declared obsolete by RFC 2854 in 2000-06 CE (almost
eight years ago!). Furthermore, interpretation of the CDO in the HTML 3.2+
`script' element was never supported by the HTML standard; it has been a
proprietary feature of *script engines* ever since.

Since I am not going to repeat myself over this, the OP should read previous
discussions on the subject where this has been explained in great detail
several times. And they should refrain from using W3School as Web
development reference, which has been proven wrong or misleading so often
around here that I lost count.


PointedEars
 
J

Jeremy J Starcher

No need to be sarcastic. Especially when you're on thin ice. The
comments vare recommended practice to prevent misunderstanding by old
browsers who don't recognoze the <script> tag. See:
http://www.w3schools.com/html/html_scripts.asp


Try WERE recommended. Unfortunately, out-dated advice keeps getting
passed down.

As tempting as w3schools may sound, take -everything- they say with a
grain of salt. They are known to be misleading/wrong on several accounts.

However, I know there
are problems with the code, that;s why I asked for help.
My debugger doidn't see anthing wrong.with the generated html page, but
I didn't know to use the java cnsole. So now I know something is wrong,
but don't know what. (I used a "button" instead of "submit", not
difference.

Most of the time, it is little issues like the ones that were addressed
that keep code from running. A syntax error in your script block can
lead to unexpected issues.
 
G

Giacomo Boffi

Thomas 'PointedEars' Lahn said:
[...] they should refrain from using W3School as Web development
reference, which has been proven wrong or misleading so often

does anybody care reposting some good, up-to-date tutorial reference
for yet another newcomer?

thank you in advance,
g
 
T

Thomas 'PointedEars' Lahn

Giacomo said:
Thomas 'PointedEars' Lahn said:
[...] they should refrain from using W3School as Web development
reference, which has been proven wrong or misleading so often

does anybody care reposting some good, up-to-date tutorial reference
for yet another newcomer?

Because Web development is a wide field, that would depend on the subject
you are exactly interested in. For example, in this almost two months old
subthread you have posted a followup in, the subject was whether it was
necessary and a Good Thing to pseudo-comment out `script' element content.

Therefore, I suggest you subscribe to this newsgroup and the newsgroups in
the comp.infosystems.www.authoring.* hierarchy, and check for new postings
regularly as the discussions in the technical Usenet newsgroups are without
doubt the most up-to-date and most factually correct tutorial you can get on
Web development (if anyone posts nonsense, it it very likely that someone
else will correct it and so on). It is not necessarily easy to understand
for a newcomer, but I think you will adapt and learn like we all still do.
thank you in advance,

You are welcome.


PointedEars
 
G

Giacomo Boffi

Thomas 'PointedEars' Lahn said:
Giacomo said:
Thomas 'PointedEars' Lahn said:
[...] they should refrain from using W3School as Web development
reference, which has been proven wrong or misleading so often

does anybody care reposting some good, up-to-date tutorial
reference for yet another newcomer?

Because Web development is a wide field, that would depend on the
subject you are exactly interested in. For example, in this almost
two months old subthread you have posted a followup in, the subject
was whether it was necessary and a Good Thing to pseudo-comment out
`script' element content.

Therefore, I suggest you subscribe to this newsgroup and the
newsgroups in the comp.infosystems.www.authoring.* hierarchy, and
check for new postings regularly as the discussions in the technical
Usenet newsgroups are without doubt the most up-to-date and most
factually correct tutorial you can get on Web development (if anyone
posts nonsense, it it very likely that someone else will correct it
and so on). It is not necessarily easy to understand for a
newcomer, but I think you will adapt and learn like we all still do.

thank you Thomas, yours is an ambitious, well conceived grand plan,
but it's oversized with respect to my modest request of a reference to
an up to date tutorial for javascript (site or book), taking into
account that i'm only a curious man, not a future web developer

en passant, i must remark that c.l.javascript's faq mentions just
only one tutorial, w3school's one...

again, thank you
g
 

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,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top