Wrapping Text in text box

  • Thread starter Thread starter Richard
  • Start date Start date
Others opinions may differ, but I can't see how you can change what the user
enters.

If it was your own text, I would suggest trying the CRLF char.- #&10; has
worked for me in an alert box
 
Here's a VB.Net function for use in an asp.NET script.
You can translate it into any other server side script language as you see
fit, or even into JavaScript for browser.
To display in the browser you need to add

replace(vbCrLf, "<br />")

somewhere after the function call



Function formatTextBox(byVal txt as string, byVal linelength as Integer) as
String

'txt is the string (from the textbox) to be formatted
'linelength is the length of the required line in characters

Dim finalstr as String = ""
Dim tmp as String = ""
Dim jj as Integer = 0

'Start a loop to parse through the string
Do While Len(txt) > linelength
tmp = Left(txt, linelength) ' assign left end to tmp
jj = InStrRev(tmp, " ") ' look for a space character to break the line
at
If jj>0 Then
'and add up to that space to the result, plus a line feed
finalstr &= left(tmp, jj-1) & vbCrLf
' remove that text from the original
txt = Mid(txt, jj+1)
Else
'If no space, just cut the string
finalstr &= tmp & vbCrLf
txt = Mid(txt, linelength + 1)
End If
Loop
'Add whatever's left (less than linelength characters)
finalstr &= txt

Return finalstr

End Function



--
Ron Symonds
Microsoft MVP (Expression Web)
http://www.rxs-enterprises.org/fp

Reply only to group - emails will be deleted unread.
 
Another solution is to not bother with wrapping according to the size of the
text box. Wrap according to the size you want THE RESULTS.

<form .blah blah>
form bits
</form>
<div style="width: 500px; margin: 0 auto; border 1px solid black;">

<!--webbot bot="Include" tag="BODY" u-include="guestlog.htm" -->

</div>

You will also need to change (in code view, at the top)

<html>

to

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

This will produce a box 500px wide with a black border, with all the results
inside it. Change the width (and border) to suit your design.
--
Ron Symonds
Microsoft MVP (Expression Web)
http://www.rxs-enterprises.org/fp

Reply only to group - emails will be deleted unread.
 
Back
Top