Replace VbCrLf in TextArea

This is a simple tutorial on how to replace VbCrLf in a textarea by <br>, so that you can format the input when displayed. 

This tutorial will show how to replace VbCrLf with <br>, so that the input of a textarea gets formatted for display.

When making a insert or update in Ultradev/MX you just have to make a small insert to make this work.

Find the code that is commented with 'create the sql insert statement' or 'create the sql update statement'.

In this code find (Ultradev):

Else
FormVal = Delim + FormVal + Delim
End If
End If

FormVal = Replace(FormVal,vbCrLf,"<br>")

If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if

In this code find (MX):

Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If

MM_formVal = Replace(MM_formVal,vbCrLf,"<br>")

If (MM_i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If

Insert the red marked replace command and the flat text in a textarea will formatted where the user has made a Return.

This is very handy when using just a form to maintain for example a news admin-tool.

That's it !

 

 

Marcellino Bommezijn

Marcellino BommezijnMarcellino Bommezijn is one of the managers at dmxzone.com. He is a contributor on the tutorials section.

Owner of Senzes Media (http://www.activecontent.nl) which provides professional services and web applications for mid-sized companies.

ActiveContent CMS is the ASP.NET Content Management solution that is used for building professional and rich-featured websites.

See All Postings From Marcellino Bommezijn >>

Comments

really simple and good work...

November 9, 2001 by Burak AYDIN
I liked very mush this trick but I wonder, do I have the possibilty to not see <br> codes in my editing pages?

how to do the opposite?

February 12, 2002 by hans grimm

this is very handy! but, when the form is opened alle the text is in one block with <br>'s in between. that is to be expected, but it would be great if it was shown with all the line breaks again, so that a non-expert can re-format it in WYSIWYG...

how can i do this?

RE: how to do the opposite?

February 13, 2002 by hans grimm

hello, I'm replying to my own post because I've found it! see below:


this between <Head> </Head>:
-----------------------------------------------------------------------
<SCRIPT language="VBScript">
<!--
function RemoveHTML(strHTM)
    dim strTmp, strTmp1, i, lngLen, charOne, ynWait4End
    strTmp=""
    strtmp1="CStr"(strHTM)
    'MsgBox(cbool(ynDoFormat = 1))

        strTmp1 = Replace(CStr(strHTM),"<br>", vbCrLf)
        strTmp = Replace(strTmp1,"<tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<TR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</TR>", vbCrLf)
        strTmp = Replace(strTmp1,"<Tr>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Tr>", vbCrLf)
        strTmp = Replace(strTmp1,"<tR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</tR>", vbCrLf)
        strTmp = Replace(strTmp1,"<TD>", "    ")
        strTmp1 = Replace(strTmp,"</TD>", "    ")
        strTmp = Replace(strTmp1,"<td>", "    ")
        strTmp1 = Replace(strTmp,"</td>", "    ")
        strTmp = Replace(strTmp1,"<Td>", "    ")
        strTmp1 = Replace(strTmp,"</Td>", "    ")
        strTmp = Replace(strTmp1,"<tD>", "    ")
        strTmp1 = Replace(strTmp,"</tD>", "    ")
        strTmp = Replace(strTmp1,"<P>", vbCrLf)
        strTmp1 = Replace(strTmp,"</P>", vbCrLf)
        strTmp = Replace(strTmp1,"<p>", vbCrLf)
        strTmp1 = Replace(strTmp,"</p>", vbCrLf)
        strTmp = Replace(strTmp1,"<Br>", vbCrLf)
        strTmp1 = Replace(strTmp,"</Br>", vbCrLf)
        strTmp = Replace(strTmp1,"<bR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</bR>", vbCrLf)
        strTmp = Replace(strTmp1,"<BR>", vbCrLf)
        strTmp1 = Replace(strTmp,"</BR>", vbCrLf)
        strTmp=""
   
 ynWait4End = False
    lngLen = Len(strTmp1)
    For i = 1 To lngLen
        charone="Mid"(strTmp1,i,1)
        If charOne="<" Then
            ynWait4End = True
            charOne=""
        End If
        If ynWait4End = True Then
            If charOne = ">" Then
                ynWait4End = False
            End If
            charOne = ""
        End If
        strTmp = strTmp & charOne
    next
    RemoveHTML= strTmp
    'spnDump.innerHTML=strTmp
End function


//-->
</SCRIPT>
------------------------------------------------------------------------
this in the form-element tag:

onFocus="NaamTextarea.value=RemoveHTML(NaamTextarea.value)"

and you are homefree

this way the textarea will display the text correctly onFocus.

have fun

RE: RE: how to do the opposite?

February 13, 2002 by hans grimm
note: 'naam.TextArea' is to be replaced by the name of your textarea...
See all 10 Comments

You must me logged in to write a comment.