Closed Bug 279758 Opened 20 years ago Closed 19 years ago

javascript: textarea_x.value.length counts 'enter' as a single character, but submit is done with \r\n (2 characters)

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 188015

People

(Reporter: remke_rutgers, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

If I understand correctly, a textarea should submit line endings as CR LF.
According to the W3C HTML 3.2 recommendation:
(the bit on textareas)
--clip--
   It is recommended that user agents canonicalize line endings to CR, LF
   (ASCII decimal 13, 10) when submitting the field's contents.
--clip--
Firefox DOES indeed submit 'enters' in a textarea as CR+LF, but javascripts
counts an 'enter' as a single character.
When trying to create a textarea with a maxlength, the text is trimmed to the
wrong length. 'Wrong' meaning 'different from server-side length'.

Reproducible: Always

Steps to Reproduce:
1. create a html form with the following javascript:
<SCRIPT LANGUAGE="JavaScript">
<!--
var maxlimit = 2;

function textCounter(fxield, countfxield) 
{
	if (fxield.value.length > maxlimit)
		fxield.value = fxield.value.substring(0, maxlimit);
	else
		countfxield.value = maxlimit - fxield.value.length;
}
//-->
</SCRIPT>
and a form with a textarea and a input type="text" field to display the count
Call the textCounter function in the onKeyDown/onKeyUp event handlers of your
textarea.
2. open the html form in your browser
3. type 'enter' twice in the textarea
4. now the textbox shows '2' (without the quotes of course)
5. if you submit the form (assuming you have some kind of server side scripting
environment) and inspect the length of the submitted textarea value, it will be
'4' (CRLFCRLF)

Actual Results:  
See in 'steps to reproduce'

Expected Results:  
I expected the client-side character count to be '4', because this is the length
of the actual string submitted.
Assignee: firefox → general
Component: General → DOM: HTML
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
dupe of bug 188015
Agreed.

*** This bug has been marked as a duplicate of 188015 ***
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → DUPLICATE
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.