Replies Back to Article
Replace VbCrLf in TextArea
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?
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
one other little thing I found out: if you do not want all tags to be stripped (such as <b> or <a>, etc.), in the script, replace 'If charOne="<" Then' by 'If charOne="" Then', and 'If charOne = ">" Then' by 'If charOne = "" Then'.
this little quirk was brought to my attention by a client who had just been entering some e-mail links in the field, and they were stripped out...
This little trick works great for Win IE, but does not work on my Mac IE? Any suggestions?
I figured it out. The VBScript does not work on the MAC because it is client side. So I use this instead...
<%
Dim strBody
strBody = rsEntry.Fields.Item("Body")
%>
<textarea name="txtBody"><%=Replace strBody,"<br>",VbCrLf)%></textarea>
Yes! I have discovered the way to do it all serverside and show the formfield with the text already formatted:
step 1:
put the script above the <html>-tags, like this:
<%
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
%>
then, you only have to put this in the formfield:
<%=RemoveHTML(Recordset1.Fields.Item("text").Value)%>
and voila..
Remember that the Replace function has more arguments that will greatly simplify your code by allowing case INSensiTive searching
strTmp1 = Replace(CStr(strHTM),"<br>", vbCrLf, 1,-1, 1)
strTmp = Replace(strTmp1,"<tr>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</tr>", vbCrLf, 1,-1, 1)
strTmp = Replace(strTmp1,"<td>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</td>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"<p>", vbCrLf, 1,-1, 1)
strTmp1 = Replace(strTmp,"</p>", vbCrLf, 1,-1, 1)
etc. . .
I'm sure someone could come up with a wildcard function to even further simplify this (something that looks for <?p> or <?t?> or <?br>) but you get the idea. Also remember that xhtml is all lowercase.
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctReplace.asp
-S