PDA

View Full Version : Replace Carriage Return in preview window


SYMBIO
12-19-2002, 03:44 PM
I'v just learned in ASP that you can replace the ascii characters for Carriage return with anything you want(<br />).

I have a preview() function on my site and this takes the form.article.value and puts it straight into the preview window.

the preview function uses a HTML string.

here is bits of the code that i used and tried>


function preview()

{

//ascii=13
//satpal2="spero"
//satpal2=form.article.value
//satpal=satpal2.replace("s","C");
//satpal=String.fromCharCode(ascii);

HTMLstring='this is the article'+satpal+' see\n';


newwindow=window.open('','Preview','left=10,top=10,width=785,height=440,scrollbars=yes');
newdocument=newwindow.document;

newdocument.write(HTMLstring);
newdocument.close();

}

help anyone?

Mhtml
12-19-2002, 04:17 PM
Is that client side?

SYMBIO
12-19-2002, 04:20 PM
yep this is javascript.

Mhtml
12-19-2002, 04:34 PM
What do you actually need to do? You didn't ask a question. :)

SYMBIO
12-19-2002, 04:37 PM
sorry, i need to be able to replace the ascii character for carriage return (enter) to "<br />" basically.

the script i posted was externally linked.

<input type="text" name="article" value="" />

Mhtml
12-19-2002, 09:53 PM
Ok, firstly ASP is server side. You can't just do something and pass it back without reloading a page.

So with ASP if you were submitting a form you would do this..

<%
TheForm = Request.Form("YourFormNameHere")
If instr(1, TheForm, chr(13), 1) > 1 Then
TheForm = Replace(TheForm, chr(13), "<br />")
End If
%>

You now have a vlaue which you can get anywhere on the page by doing <%=TheForm%> or maybe insert into a database, whatever you want to do.

whammy
12-20-2002, 01:47 AM
mystring = Replace(mystring,vbCrLf,"<br />")

I have this as a function (i.e. myvariable = VbCrLfToBreak(myvariable))... see:

http://www.solidscripts.com/downloads/regex.txt

P.S. I have updated this example script somewhat, but have not yet replaced it, I will have to do so tomorrow...

SYMBIO
12-20-2002, 09:19 AM
sorry i just realised that i posted this to the ASP forum. I already knew how to do it in ASP.

i needed to know how to do it in javascript. SO sorry for the confusion.

i guess i will post this again in the javascript area. i know ASP is server-side. Javascript is Client Side.

once again sorry.

whammy
12-21-2002, 01:47 AM
mystring=mystring.replace("\n","<br />");

I think... argh it's been to long since I've done this type of thing in javascript but that should give you the right idea if it doesn't work...