• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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;
}
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic