473,591 Members | 2,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to force carriage return in textarea

i need to force a carriage return with a textarea field at X number of
characters. anybody know how to do this?

tks
Jul 23 '05 #1
8 46158
Steven wrote:
i need to force a carriage return with a textarea field at X number of
characters. anybody know how to do this?


onchange, read its value, insert the returns, and move on.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2

"Randy Webb" <Hi************ @aol.com> wrote in message
news:qZ******** ************@co mcast.com...
Steven wrote:
i need to force a carriage return with a textarea field at X number of
characters. anybody know how to do this?
onchange, read its value, insert the returns, and move on.

whta's the carriage return?

sTxtBoxValue = sTxtBoxValue + "\r"?


--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
Steven wrote:

whta's the carriage return?

sTxtBoxValue = sTxtBoxValue + "\r"?

It depends where you mean to display the text. Normally you don't need
to insert carriage returns, but if it's for display in HTML page, and
you need to force a break.
sTxtBoxValue = sTxtBoxValue + "<BR>"?
But where to place the break can become problematic.

You may need to transform the text into an array.

arr=text.split(/\s+/)
Then count the characters in each array entry, and set up some kind of
"while" loop.
Mick
Mick

Jul 23 '05 #4

"Mick White" <mw***********@ rochester.rr.co m> wrote in message
news:sU******** ********@twiste r.nyroc.rr.com. ..
Steven wrote:

whta's the carriage return?

sTxtBoxValue = sTxtBoxValue + "\r"?
It depends where you mean to display the text. Normally you don't need
to insert carriage returns, but if it's for display in HTML page, and
you need to force a break.
sTxtBoxValue = sTxtBoxValue + "<BR>"?


<br> won't work inside a textarea. i need to start a new line withing
textarea, just as though the user has hit the enter key. in vb, i could use
a 'sendkeys' function to mimic keyboard behaviour. i need to do the same
thing here. this doesn't work:

<script language="javas cript">
function forceReturn(iMa xLength, sValue){
if (sValue.length > iMaxLength){
sValue = sValue + "\r";
}
}
</script>

<textarea name="txt" onKeyUp="forceR eturn('5', this.value);" rows="5"
cols="10"></textarea>


But where to place the break can become problematic.

You may need to transform the text into an array.

arr=text.split(/\s+/)
Then count the characters in each array entry, and set up some kind of
"while" loop.
Mick
Mick

Jul 23 '05 #5
Steven wrote:
[snip]
<script language="javas cript">
function forceReturn(iMa xLength, sValue){
if (sValue.length > iMaxLength){
sValue = sValue + "\r";
}
}
</script>

<textarea name="txt" onKeyUp="forceR eturn('5', this.value);" rows="5"
cols="10"></textarea>


<script type="text/javascript">
function forceReturn(iMa xLength,sValue) {
if (sValue.value.l ength > iMaxLength){
sValue.value += "\r";
}
}
</script>

<textarea name="txt" onKeyUp="forceR eturn('5', this);" rows="5"
cols="10"></textarea>

You can't change the value using :
sValue = sValue + "\r";
(sValue is a reference not an object). Better to pass the textfield
object to your function.

Mick
Jul 23 '05 #6
Steven wrote:
i need to force a carriage return with a textarea field at X number of
characters. anybody know how to do this?


You can't reliably do this, though you may be able to get it to work in
a particular browser, but certainly not all.

One of the biggest problems is that you have no idea where the
insertion point is. You can't simply add a return after 5 keystrokes,
or to the end of the string if it's more than 5 characters long.

Say you add an onkeydown event the checks the number of characters, and
when the user types a 5th character, you add a return to the end of the
string to add a 6th character.

But the cursor is still at the 5th, before your return, so any further
input will go before your return - you can't move the insertion point
programmaticall y.

Another is if the user puts the insertion point somewhere else in the
string and starts typing - say changing the first 5 character phrase.
you now must get rid of all your returns and put them back in the right
place - each time a key is pressed.

There are many more scenarios where this will fail, as no doubt you
have discovered.

Rob.
Jul 23 '05 #7
Mick White wrote:

<script type="text/javascript">
function forceReturn(iMa xLength,sValue) {
if (sValue.value.l ength > iMaxLength){
sValue.value += "\r";
}
}
</script>

The above script is nonsense, sorry. Notwithstanding Rob's caveats,
the following is an improvement (It will create a column of text 5
characters wide)

<script type="text/javascript">
function forceReturn(iMa xLength,sValue) {
if (sValue.value.l ength % iMaxLength==5){
sValue.value += "\r";
}
}
</script>
Mick
Jul 23 '05 #8
Mick White wrote:
Mick White wrote:

<script type="text/javascript">
function forceReturn(iMa xLength,sValue) {
if (sValue.value.l ength > iMaxLength){
sValue.value += "\r";
}
}
</script>


The above script is nonsense, sorry. Notwithstanding Rob's caveats, the
following is an improvement (It will create a column of text 5
characters wide)

<script type="text/javascript">
function forceReturn(iMa xLength,sValue) {
if (sValue.value.l ength % iMaxLength==5){
sValue.value += "\r";
}
}
</script>


I have a script somewhere that does what the OP Wants. But it works
onChange. These are the basic steps:

1) Read the value.
2) Find the nth character, where n is the desired width in characters.
3) Is the nth character a space?
If not a space: find the lastindexOf a space.Grab the substrings.
If a space:
Grab a substring from 0 to n-1, grab the substring from n to string length.
Save the first substring in an array.
Repeat with the remaining string.

Now, put your array back together with a new line character with join().
Put the string back into the textarea.

It will only work with a fixed width font.

Ahh, here it is:
http://members.aol.com/_ht_a/hikksno...ypingText.html

Its primitive at best (could be refined). But it uses a DIV tag and BR/P
tags instead of \n\r but the insertBR function could easily be modified
to work with newlines.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #9

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

Similar topics

3
9277
by: Canes_Rock | last post by:
The information posted at: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=slrnarv28n.e4j.TuxTrax%40fortress.tuxnet&rnum=1&prev=/groups%3Fq%3Dsuppress%2Bcarriage%2Breturn%2Bgroup:comp.lang.python.*%26hl%3Den%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.python.*%26selm%3Dslrnarv28n.e4j.TuxTrax%2540fortress.tuxnet%26rnum%3D1 seemed to provide a solution to eliminating the line feed and causing a carriage return for the text displayed...
2
4120
by: Andrew Chanter | last post by:
I have a VBA function that returns a string including "vbcr" (VB Carriage Return) to seperate a list into multiple rows, eg Item1 & vbcr & Item2 & vbcr & Item3 This works as planned in the immediate window, producing a list where a Carriage Return follows each item. But when I output the result into either an Access query or form, instead of carriage returns I get little square symbols between each of the items. Is anyone able to tell...
2
2941
by: eagleofjade | last post by:
I am trying to import data from a Word document into an Access table with VBA. The Word document is a form which has various fields. One of the fields is a field for notes. In some cases, this note field contains carriage returns. When I import a note field that has carriage returns, what shows up in the Access field are vertical black lines where the carriage return should be.
1
2185
by: VMI | last post by:
If I want to separate a string in a web textbox so that it takes several lines, how can do it? In a Windows textbox, I only needed to add the "\r\n" to the string for the carriage return. Apparently it's not the same with the web textbox. Thanks.
3
3375
by: Dinsdale | last post by:
I have an xml file that is read into an object using serialization. One of the objects has a string field called delimeter that I want to contain a carriage return. Instead of trying to include the carriage return, I used "\r" thinking that when it was read back into the object it would be interpreted as a carriage return. Instead, I am getting the string literal instead of the escape sequence. Does anybody have a slick way of telling it...
0
1813
by: J.Marsch | last post by:
I am having a problem in which ASP.Net web services are corrupting my data. I know that my problem is related to the standard way of encoding carriage return linefeeds, so I need to figure out how to correctly encode them. I am trying to return XML strings that were generated by calling DataTable.WriteXml() from my web service, and then using DataTable.ReadXml to deserialize the data. The problem is that some of the data in the...
1
6258
by: Blue | last post by:
This JS limits the input characters into the form. How do I modify it so that it also allows CARRIAGE RETURN and BACKSPACE (for making text correction)? Due to the template engine I am using, I cannot use IF/ELSE statement. ============================== <form> <textarea name="event_description" ONKEYPRESS="if (document.layers)
11
12579
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message so the user can edit the default email message body before sending the message. But when I populate the large text box (txtBody), I can't get it to include the carriage returns. I've tried vbNewLine, vbCrLf, Chr(10) and Chr(13). I've got the...
0
7870
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
8236
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
8362
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
6639
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5732
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3850
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...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1465
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1199
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.