473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Editable Textarea

Hello all, looking for some help here!

I've got a page on a website I'm developing that contains a textarea.
The textarea will allow users of the site to enter a description of an
item.

When they submit the form that contains the textarea, the textarea and
other form elements data are stored in a database.

So far so good.

My problem concerns carriage returns, new lines, line feeds or whatever
else you want to call them :-)

I want them preserved, so when the user wants to edit the description of
the item, the format of the description is displayed exaclty as it was
entered.

The problem is that HTML renders the carriage returns as white space, so
when the database is read and the textarea populated with the
description field, the carriage returns are lost.

I have tried the ASP REPLACE function to replace carriage returns with
<br>, but the code below actually displays all the <br>'s.

<%=Replace(myRecordset.Fields.Item("myField").Valu e,Chr(13),"<br>")%>

I played around with different combinations of chr(13) and vbcrlf and I
managed to get the textarea to display the description as it was entered
with carriage returns, but upon further testing and editing of the
description, because of the REPLACE function, the number of carriage
returns was doubling each time!

I'm sure this is a simple problem to fix, but I just can't find it at
the moment - I hope someone can help.

Many thanks,

Robine

*** Sent via Developersdex http://www.developersdex.com ***
Jan 26 '06 #1
5 2718
Robine wrote on 26 jan 2006 in microsoft.public.inetserver.asp.general:
<%=Replace(myRecordset.Fields.Item("myField").Valu e,Chr(13),"<br>")%>

I played around with different combinations of chr(13) and vbcrlf and I
managed to get the textarea to display the description as it was entered
with carriage returns, but upon further testing and editing of the
description, because of the REPLACE function, the number of carriage
returns was doubling each time!


Analyzing the problem with clientside javascript:

==========
<textarea id=t1 style='height:100px;'>
a b c
dddd
eee
f g h
</textarea>

<textarea id=t2 style='height:100px;'>
</textarea>

<br>
<button onclick="
t=
document.getElementById('t2').value=
document.getElementById('t1').value;
alert(t.replace(/\r\n/g,'=crlf='))
">click</button>
==========

Shows that the textarea value [in IE6] is VbCrLf [= chr(13)&chr(10)]

Beter show us the relevant code example,
because I think the reduplication is just a logical coding error.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 26 '06 #2
Robine wrote:
My problem concerns carriage returns, new lines, line feeds or
whatever else you want to call them :-)

This page should show you what needs to be done:
<%
dim ar, s
ar=array("a","b","c")
s=join(ar,vbcrlf)
%>
<HTML>
<BODY>
<TEXTAREA rows=6 cols=20 >
<%=s%>
</TEXTAREA>
</BODY>
</HTML>

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 26 '06 #3
And for a function that may be able to help:

Function jpsvbFixHTMLInclSpaceBR(pvarFld)
' Dim var.
Dim varFld

' Quick exit if blank.
If IsNull(pvarFld) Or (Len(pvarFld) = 0) Then
jpsvbFixHTMLInclSpaceBR = pvarFld
Exit Function
End If

' Set var.
varFld = pvarFld

' Fix HTML.
varFld = Server.HTMLEncode(varFld)

' Convert each space and space to space and &nbsp;
varFld = Replace(varFld, " ", " &nbsp;")

' Convert all vbCrLf to <br>.
' (This is the same as converting Chr(13) & Chr(10) to <br>.)
varFld = Replace(varFld, vbCrLf, "<br>")

' Set var.
jpsvbFixHTMLInclSpaceBR = varFld
End Function

Best regards,
-Paul
www.Bullschmidt.com - Freelance Web and Database Developer
www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

Jan 29 '06 #4
Chi
HERE IS YOUR ANSWER...
You upload normally, its when you display it that makes the difference..

Dim i, se As Integer
i = str.IndexOfAny(ControlChars.CrLf)

While Not i = -1
str = str.Insert(i, "<br /><br />")
se = str.Length 'get the new length of the string
If i + 15 >= se Then
Exit While
End If
If str.IndexOfAny(ControlChars.CrLf, i + 15) >= se Then
'See if it has reached the end
Exit While
Else
i = str.IndexOfAny(ControlChars.CrLf, i + 15)
End If
End While
label.Text = str
End If

HOPE THIS HELPED
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
Robine wrote:
My problem concerns carriage returns, new lines, line feeds or
whatever else you want to call them :-)

This page should show you what needs to be done:
<%
dim ar, s
ar=array("a","b","c")
s=join(ar,vbcrlf)
%>
<HTML>
<BODY>
<TEXTAREA rows=6 cols=20 >
<%=s%>
</TEXTAREA>
</BODY>
</HTML>

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Feb 1 '06 #5
Chi wrote:
HERE IS YOUR ANSWER...


Only in the unlikely event that the user is using ASP.Net

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 1 '06 #6

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

Similar topics

1
by: Volt | last post by:
is there any way to select and mark part of text in textarea by regular expression? i need to select the first string in textarea whitch is like xxxxx,xxx where x is any character
7
by: deko | last post by:
SELECT tblTxAcct.TxAcctName, tblTxType.TxTypeName, Nz(qryTxAcctListCt.TxCount, 0) AS TxCt FROM (tblTxAcct INNER JOIN tblTxType ON tblTxAcct.TxType_ID=tblTxType.TxType_ID) LEFT JOIN qryTxAcctListCt...
4
by: TJS | last post by:
can the rows and columns of a textarea element with an id be changed on the fly ? if so is there an example ?
1
by: Venki | last post by:
I have a textbox to enter an email address followed by a telephone textbox. The email has a regularexpressionvalidator and a requiredfieldvalidator. The ReqField works fine, but if I put in an...
6
by: Hako | last post by:
Hello All, I have a function to set readonly or editable of a textctrl. I'd like to make the textctrl initial set readonly and use other event funciton to set editable of the textctrl but it...
34
by: Luke | last post by:
Hi! I am new to PHP but I am a very experienced in Perl/CGI/templates. I work in medical informatics when we deal with very large data collection forms. Some of them have over 1000 elements!...
3
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to...
0
by: muchinger | last post by:
All, I create 2 combo boxes on a page: an editable one and a non-editable one. Both of them have the same string items which are too long to entirely fit into the combo box. E. g. the size of...
1
by: Termin_Terminator | last post by:
Hello everybody, I am using an HTML anchor "<A contenteditable=true></A>" element with the property 'contenteditable=true' to make it editable for the user. Inside JScript or JavaScript I am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.