|
Can anyone translate the following code (ASP/VBScript) to ASP/JScript for me? Thanks
<%
Dim Address
Address = Request.Form("Address")
Address = Replace(Address, vbCrLf, "<BR>")
Address = Replace(Address, " ", " ")
%>
|
|
|
Here is some client-side javascript to demonstrate this technique. The secret is to use a regular expression to represent the carriage return/line feed:
rExp = /\r\n/g'
This line says to find a carriage return (\r) followed by a line feed (\n) and to find all occurances of this combination (g for globally).
Simply copy and paste this code as an html file, then run it. Enter your test text in the text box then click "Test". Try entering content with no line breaks, one line break, then multiple line breaks.
-----------------------------
<script language=javascript>
function Test() {
rExp = /\r\n/g;
myString = document.forms[0].elements[0].value;
alert(myString);
myString = myString.replace(rExp,"<br>");
alert(myString);
}
</script>
<form>
<textarea cols=40 rows=8></textarea>
<br>
<input type=button value="Test" onclick="Test()">
</form>
-----------------------------
Troy Wolf http://www.ShinySolutions.com is the answer to your hosting and web development needs.
|
|
|
|
|
|
|
|
|
// |