• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Text formating in HTML - Text area

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a webpage where user enters long text in text field, after few UI interatctions(workflow) I take the text and dislplay this a string, I am facing a problem that text doesnt appear same as was entered instead appears as long text I tried <pre> tag but it didnt help much.

I am usign only HTML and Javascript and nothing else
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basic idea:

var strOut = myStr.replace(/\n/gi,"<br/>");

Eric
 
Sri Anand
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply,
this helped me, I have one more problem I have 2 text areas in my form after i fill in my form, i have a print view (not print preview of browser)where i show only selected html fields(check boxes etc.,) in this view i show the content entered in text area in a div hiding textarea i make use of <pre> tag to show in the same way it was entered however the font of the text taken from textarea is smaller and different i tried using <font> tag but didnt help any suggesting over this

[ August 27, 2007: Message edited by: Raghunandan Mamidala ]
[ August 27, 2007: Message edited by: Raghunandan Mamidala ]
 
Sri Anand
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a solution posting it here may be someone else can save time if they come across similar situation

function decorateText(text){
var splitString=text.split("\n");
var FormattedText="";
if(splitString.length>0){
for(i=0;i<splitString.length;i++){
if(splitString[i].length>179){
splitString[i]="<wbr>" + splitString[i] +"</wbr>";
}
FormattedText=FormattedText + splitString[i] + "<br>";
}
}else{
FormattedText="<wbr>" + myStr + "</wbr>"
}
return FormattedText;
}
 
A lot of people cry when they cut onions. The trick is not to form an emotional bond. This tiny ad told me:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic