Apollyein Posted December 23, 2005 Share Posted December 23, 2005 I want to use CSS, Javascript, and HTML to make a resource for story formatting. That is, making a story appear as though it was taken straight from the bible.I have a text box. I pull the info from the text box, and make it a string. I take said string, find the first letter, <span> it, and then add the rest.My code is basically a copy and paste Frankenstein of W3 and Javascript for the Total Non Programmer tutorials, with hours of tinkering to make it do what I want.My issue:The code ignores all new lines. It just displays as one big text brick.My code is as follows: <HTML><head><style type="text/css">span{float:left;width:0.7em;font-size:400%;font-family:algerian,courier;line-height:80%;}</style><script LANGUAGE="JavaScript"><!-- Beginning of JavaScript -function MsgBox (textstring) {alert (textstring) }function MyWindow(message) { //Define contents of page first=message.slice(0,1) contents= '<html>'+ '<head>'+ '<style type="text/css">'+ 'span'+ '{'+ 'float:left;'+ 'width:1.4em;'+ 'font-size:400%;'+ 'font-family:Celticmd,algerian,courier;'+ 'line-height:80%;'+ '}'+ '</style>'+ '<body bgcolor="white"><br><br><br><br>'+ '<p><span>'+first+'</span> '+ message '</p>'+ '</body>'+ '</HTML>' //Create new Window options = "toolbar=1,status=1,menubar=1,scrollbars=1," + "resizable=1,width=900,height=600"; newwindow=window.open("","FormattedStory", options); newwindow.document.write(contents); newwindow.document.close();}// - End of JavaScript - --></SCRIPT></head><body><center><textarea rows="30" cols="80" id="inputstory">Copy and Paste Your Story Into This Box.</textarea><br><INPUT NAME="submit" TYPE=Button VALUE="Format" onClick="MyWindow(inputstory.value)"></center></HTML Any ideas or help?I'm a total n00b, and the only thing I can think of without requiring a special syntax is to search for a carriage return and splice at that character. Problem is, I don't know how to search for a carriage return!~Apollyein Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 23, 2005 Share Posted December 23, 2005 \r is carriage return. Link to comment Share on other sites More sharing options...
Apollyein Posted December 23, 2005 Author Share Posted December 23, 2005 Thanks for the quick reply!Erm...Does that only work when I type it in, or does it also work when it's being searched for in the string?~Apollyein Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 25, 2005 Share Posted December 25, 2005 I don't understand. If you document.write a /r with javascript, it will create a carriage return. Link to comment Share on other sites More sharing options...
hacknsack Posted December 26, 2005 Share Posted December 26, 2005 I think what Apollyein is after is a way to convert the new lines in the textarea to a "html" line break.We can use a regular expression and check for new lines and convert that to "<br>". <html><head><style type="text/css">span{float:left;width:0.7em;font-size:400%;font-family:algerian,courier;line-height:80%;}</style><script LANGUAGE="JavaScript"><!-- Beginning of JavaScript -function MyWindow(message) {//Define regular expression for line breakre = /(\r\n)|(\n)/g//Define contents of pagefirst= '<span>' + message.substring(0,1) + '</span>'message = message.substring(1)contents='<html>'+'<head>'+'<style type="text/css">'+'span'+'{'+'float:left;'+'padding-right: 12px;'+'font-size:200%;'+'font-family:Celticmd,algerian,courier;'+'line-height:80%;'+'}'+'</style>'+'<body bgcolor="white"><br><br><br><br>'+'<p><span>'+first+'</span> '+message'</p>'+'</body>'+'</HTML>'//Create new Windowoptions = "toolbar=1,status=1,menubar=1,scrollbars=1," +"resizable=1,width=900,height=600";newwindow=window.open("","FormattedStory", options);newwindow.document.write(contents.replace(re, "<br>\n"));newwindow.document.close();}// - End of JavaScript - --></SCRIPT></head><body><center><form><textarea rows="30" cols="80" id="inputstory">Copy and Paste Your Story Into This Box.</textarea><br><INPUT NAME="submit" TYPE=Button VALUE="Format" onClick="MyWindow(this.form.elements['inputstory'].value)"></form></center></body></html> Thanks, Link to comment Share on other sites More sharing options...
Apollyein Posted December 26, 2005 Author Share Posted December 26, 2005 Thank you. That's exactly what I was after.I wanted to know how; You did it for me. Thanks.Now I'll get to work decoding it so I know how you did it.Thanks again.~Apollyein Link to comment Share on other sites More sharing options...
Skemcin Posted December 26, 2005 Share Posted December 26, 2005 \r is carriage return. \n is also a return is it not? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now