HighDots Forums  

Loading into TEXTAREA skips lines ?

Javascript JavaScript language (comp.lang.javascript)


Discuss Loading into TEXTAREA skips lines ? in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
David
 
Posts: n/a

Default Loading into TEXTAREA skips lines ? - 09-25-2007 , 06:16 AM






Hi,

I have a simple form which uses the following code to add lines into a
textarea field from a button
The problem is that it always seems to begin on the 3rd line, i.e.
skips line 1 & 2 in the textarea box

I would like it to start at line 1, how can I adjust the code to do
this ?


-----------------------------------------

<SCRIPT language="JavaScript">
<!--
function addItem(){

var Unit = document.schedule.schedule_update.value
if (Unit=='')
{Unit += document.formname.quantity.value + " x "
+document.formname.list2.value}
else
{Unit += '\n' + document.formname.quantity.value + " x " +
document.formname.list2.value}
document.schedule.schedule_update.value = Unit
}

//-->
</SCRIPT>


------------------------------------------------


Many thanks

David


Reply With Quote
  #2  
Old   
news@chthonic.f9.co.uk
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 09:32 AM






On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
Quote:
Hi,

I have a simple form which uses the following code to add lines into a
textarea field from a button
The problem is that it always seems to begin on the 3rd line, i.e.
skips line 1 & 2 in the textarea box

You haven't provided any HTML, so my guess is that just that,
a guess, but... I'd guess your markup has the TextArea element
defined with whitespace before the closing tag. Your javascript is
testing
to see if the textarea's value is empty, but it isn't, so it's
adding an extra newline character before adding your text.


Quote:
I would like it to start at line 1, how can I adjust the code to do
this ?

-----------------------------------------

SCRIPT language="JavaScript"
Use <script type="text\javascript">

Quote:
!--
Don't use HTML comments in scripts. At best they do nothing, at
worst they'll prevent your script executing.

[rest of function snipped - it's not pretty, but it works]

Quote:
document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose

Mike



Reply With Quote
  #3  
Old   
Lee
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 10:24 AM



David said:
Quote:
Hi,

I have a simple form which uses the following code to add lines into a
textarea field from a button
The problem is that it always seems to begin on the 3rd line, i.e.
skips line 1 & 2 in the textarea box

I would like it to start at line 1, how can I adjust the code to do
this ?


-----------------------------------------

SCRIPT language="JavaScript"
!--
function addItem(){

var Unit = document.schedule.schedule_update.value
if (Unit=='')
{Unit += document.formname.quantity.value + " x "
+document.formname.list2.value}
else
{Unit += '\n' + document.formname.quantity.value + " x " +
document.formname.list2.value}
document.schedule.schedule_update.value = Unit
}

//--
/SCRIPT
The code as written (in the 1990's, I would guess) will:
If there is no text in the text box, insert the new text.
If there is text in the text box, insert a NEWLINE and
then append the new text.
It doesn't skip anything.
What do you want it to do in each of those two cases?


--



Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 12:49 PM



news (AT) chthonic (DOT) f9.co.uk wrote:
Quote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"

Use <script type="text\javascript"
Correct is

<script type="text/javascript">

(This is the Internet, not Micro$~1 Windows.)

Quote:
document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose
The above should read

document.forms["formname"].elements["quantity"].value

to be both standards compliant and backwards compatible.


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


Reply With Quote
  #5  
Old   
Randy Webb
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 01:06 PM



Thomas 'PointedEars' Lahn said the following on 9/25/2007 12:49 PM:
Quote:
news (AT) chthonic (DOT) f9.co.uk wrote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"
Use <script type="text\javascript"

Correct is
According to the W3C Validator, it is. According to any standards that
define MIME Types for the script element it isn't correct.

Quote:
script type="text/javascript"

(This is the Internet, not Micro$~1 Windows.)

document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose

The above should read

document.forms["formname"].elements["quantity"].value

to be both standards compliant and backwards compatible.
Nonsense.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #6  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 01:48 PM



Randy Webb wrote:
Quote:
Thomas 'PointedEars' Lahn said the following on 9/25/2007 12:49 PM:
news (AT) chthonic (DOT) f9.co.uk wrote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"
Use <script type="text\javascript"
Correct is

According to the W3C Validator, it is.
The W3C Validator uses an SGML or XML parser that can only validate a
document resource against a DTD, and the (X)HTML (4.01/1.x) DTDs only
specify the attribute value to be CDATA (which is fulfilled here):

http://www.w3.org/TR/html401/sgml/loosedtd.html
http://www.w3.org/TR/html401/sgml/framesetdtd.html
http://www.w3.org/TR/html401/sgml/dtd.html
(search for "ELEMENT SCRIPT")

http://www.w3.org/TR/xhtml1/dtds.htm...nal.dtd_script
http://www.w3.org/TR/xhtml1/dtds.htm...set.dtd_script
http://www.w3.org/TR/xhtml1/dtds.htm...ict.dtd_script

http://www.w3.org/TR/2001/REC-xhtml1...#a_xhtml11_dtd
(search for "Scripting Module")
http://www.w3.org/TR/xhtml-modulariz...dule_Scripting

I would still consider it not recognizing a violation of the basic media
type syntax a bug, and the further checking against that syntax well-defined
in RFC 2054, subsection 5.1, should be reported as a request for enhancement:

http://validator.w3.org/feedback.html

Quote:
According to any standards that define MIME Types for the script
element it isn't correct.
Exactly.

Quote:
document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose
The above should read

document.forms["formname"].elements["quantity"].value

to be both standards compliant and backwards compatible.

Nonsense.
It is _not_ nonsense. (As you should know already,) W3C DOM Level 2 HTML
also specifies the ECMAScript binding for the interfaces defined there:

http://www.w3.org/TR/DOM-Level-2-HTM...t-binding.html

And the object that implements the HTMLDocument interface in conforming
implementations can be currently referred to with `document' or
`window.document' in all relevant DOM implementations.

(As you also should know already,) this referencing of items of a collection
or node list (with bracket property accessor syntax) is supported since DOM
Level 0 (IE3/NN3):

http://msdn2.microsoft.com/en-us/library/ms531073.aspx
http://research.nihonsoft.org/javasc...c1.htm#1010814
http://hal.ific.uv.es/informatica/ma...t.html#1193750


PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>


Reply With Quote
  #7  
Old   
Randy Webb
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-25-2007 , 04:56 PM



Thomas 'PointedEars' Lahn said the following on 9/25/2007 1:48 PM:
Quote:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 9/25/2007 12:49 PM:
news (AT) chthonic (DOT) f9.co.uk wrote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"
Use <script type="text\javascript"
Correct is
According to the W3C Validator, it is.

The W3C Validator uses an SGML or XML parser that can only validate a
document resource against a DTD, and the (X)HTML (4.01/1.x) DTDs only
specify the attribute value to be CDATA (which is fulfilled here):
<snipped lots of URL's I don't care about>

I was referring to your supposition that the only acceptable script
element was with a type attribute that, as you know, has no
defined/standardized MIME types for it. The only one acceptable is
"text/javascript" and, unless you name your phantom UA, the only thing
that complains about it is the W3C Validator.

Quote:
According to any standards that define MIME Types for the script
element it isn't correct.

Exactly.
And that "Exactly" is because, as you are well aware, there are *no*
*defined* MIME types for the type attribute for a script element.

Quote:
document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose
The above should read

document.forms["formname"].elements["quantity"].value

to be both standards compliant and backwards compatible.
Nonsense.

It is _not_ nonsense. (As you should know already,) W3C DOM Level 2 HTML
also specifies the ECMAScript binding for the interfaces defined there:

http://www.w3.org/TR/DOM-Level-2-HTM...t-binding.html
And as you should know already, I won't repeat my opinion of a bunch of
useless worthless text on a webpage.

The *only* time bracket notation is preferred over dot notation is if
the identifier has certain characters in it. It has nothing to do with
"standards compliant" and it sure as Hades has nothing to do with
"backwards compatibility".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #8  
Old   
news@chthonic.f9.co.uk
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-26-2007 , 05:31 AM



On Sep 25, 5:49 pm, Thomas 'PointedEars' Lahn <PointedE... (AT) web (DOT) de>
wrote:
Quote:
n... (AT) chthonic (DOT) f9.co.uk wrote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"

Use <script type="text\javascript"

Correct is

script type="text/javascript"

(This is the Internet, not Micro$~1 Windows.)

Oops. Typo. I switch between OS's so often I have to
think long and hard which slash is which. Call it
path dyslexia. Sad, isn't it?

Mike



Reply With Quote
  #9  
Old   
Dr J R Stockton
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-26-2007 , 11:53 AM



In comp.lang.javascript message <0qmdneBpR4sQ6GTb4p2dnAA (AT) giganews (DOT) com>,
Tue, 25 Sep 2007 16:56:10, Randy Webb <HikksNotAtHome (AT) aol (DOT) com> posted:

Quote:
The *only* time bracket notation is preferred over dot notation is if
the identifier has certain characters in it. It has nothing to do with
"standards compliant" and it sure as Hades has nothing to do with
"backwards compatibility".

Bracket notation is required if the name contains characters
incompatible with dot notation, AND if the name needs to be computed at
run time rather than being supplied at write time. See FAQ notes.

You can prefer it whenever you like.

Personally, I'd use dot notation whenever practical (which does not
include using eval to make it possible.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.


Reply With Quote
  #10  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: Loading into TEXTAREA skips lines ? - 09-26-2007 , 02:23 PM



Randy Webb wrote:
Quote:
Thomas 'PointedEars' Lahn said the following on 9/25/2007 1:48 PM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 9/25/2007 12:49 PM:
news (AT) chthonic (DOT) f9.co.uk wrote:
On Sep 25, 11:16 am, David <davidgor... (AT) scene-double (DOT) co.uk> wrote:
SCRIPT language="JavaScript"
Use <script type="text\javascript"
Correct is
According to the W3C Validator, it is.
The W3C Validator uses an SGML or XML parser that can only validate a
document resource against a DTD, and the (X)HTML (4.01/1.x) DTDs only
specify the attribute value to be CDATA (which is fulfilled here):

snipped lots of URL's I don't care about
You better should care about them as they also prove your following
statements wrong.

Quote:
I was referring to your supposition that the only acceptable script
element was with a type attribute that, as you know, has no
defined/standardized MIME types for it.
If I knew that, I would know nonsense.

http://PointedEars.de/scripts/test/mime-types

Quote:
The only one acceptable is "text/javascript"
It is the only one currently *feasible* for ECMAScript-conforming scripting
in (X)HTML on the Web. It is not the only one acceptable. In SVG, for
example, that value should be "text/ecmascript". (I might add that to the
aforementioned test case.)

Quote:
and, unless you name your phantom UA, the only thing that complains
about it is the W3C Validator.
The W3C Validator does not complain about `<script type="text/javascript">'.

Quote:
According to any standards that define MIME Types for the script
element it isn't correct.
Exactly.

And that "Exactly" is because, as you are well aware, there are *no*
*defined* MIME types for the type attribute for a script element.
Utter nonsense. All media types denoting a script language would be valid.
They don't even have to be registered, as long as the syntax for media type
identifiers as referred to by the (X)HTML standard(s) is followed.

Quote:
document.formname.quantity.value
Do you really have a form called "formname"? Each to his own I suppose
The above should read

document.forms["formname"].elements["quantity"].value

to be both standards compliant and backwards compatible.
Nonsense.
It is _not_ nonsense. (As you should know already,) W3C DOM Level 2 HTML
also specifies the ECMAScript binding for the interfaces defined there:

http://www.w3.org/TR/DOM-Level-2-HTM...t-binding.html

And as you should know already, I won't repeat my opinion of a bunch of
useless worthless text on a webpage.
It is not some "web page", it is a normative document from a Web standard.

Quote:
The *only* time bracket notation is preferred over dot notation is if
the identifier has certain characters in it. It has nothing to do with
"standards compliant"
Yes, it has. The item() and namedItem() methods of objects implementing the
HTMLCollection interface are to be triggered through the bracket property
accessor syntax. That for identifiers this works, too, in some UAs, is
proprietary behavior due to the need for backwards-compatibility there.

Quote:
and it sure as Hades has nothing to do with "backwards compatibility".
It has a lot to do with it. The bracket property accessor syntax that is
required when following the standard published later *also* works with
script engines that were released before that do not differentiate between
the language and the DOM, as it was until including JavaScript 1.3.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.