Replace VbCrLf in TextArea
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 = Replace(FormVal,vbCrLf,"<br>") If (i <> LBound(MM_fields)) Then In this code find (MX): Else MM_formVal = Replace(MM_formVal,vbCrLf,"<br>") If (MM_i <> LBound(MM_fields)) Then 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 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.
Comments
really simple and good work...
how to do the opposite?
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?
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?
You must me logged in to write a comment.