Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically inserting a newline in a <textarea>, <span>, or <div>

Status
Not open for further replies.

JScannell

Programmer
Jan 9, 2001
306
US
I can't get anything to work!! I want to produce a list of upcoming birthdays for my clients. I have tried a textarea, span, and div. But there seems to be now way to produce a list like this:
Upcoming Birthdays:
Johnny Jones 10/31/2021
Anita Smith 11/5/2021

I have tried several values for a newLine variable including 'BR', Slash-r and Slash-n, Ampersand 13 and Ampersand 10 but no matter what I try, all I get is the textual value of the newLine variable!

so what you see above would come out as: Upcoming Birthdays:[newLine value] Johnny Jones 10/31/2021[newLine value] Anita Smith 11/5/2021

See the attachment. In it is my actual code as well as the output.

Thanks in advance,
Jerry

Jerry Scannell
 
 https://files.engineering.com/getfile.aspx?folder=b08d2382-afd0-4bcb-a944-23c96f3a7351&file=InsertingNewLine.pdf
It still doesn't work. I had previously tried several "new line" values and all it did was display that text as if it was just text. I posted an attachment the other day that explained how I tried several "new line" iterations with the same results. It just displayed the text and not the interpretation of the "newLine" value.

I've attached a new document now.



Jerry Scannell
 
 https://files.engineering.com/getfile.aspx?folder=5dc745e3-54d4-4ab0-aab0-3766f9bb87c8&file=Code_lines.pdf
Hi

I am still confused abit regarding your intention. Anyway, there are 2 possibilities :
[ul]
[li]Use a DOM element : append to its [tt].innerHTML[/tt] property and use [tt]<br>[/tt] for line break[/li]
[li]Use a [tt]textarea[/tt] : append to its [tt].value[/tt] property and use [tt]'\n'[/tt] for line break[/li]
[/ul]
See them in action on JSFiddle :

Feherke.
feherke.github.io
 
The purpose is to populate the upcoming client birthdays after.logging in. I want one per line in the textarea.

Jerry Scannell
 
as this is post login, I assume you have some server side code handling that, so why not add this in there as well ? If you have to use JS then feherke's examples should do what you need.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top