+ 2

New lines?

Is it possible to have the output of the textarea display new lines? like this ? If so, how? https://code.sololearn.com/W5AR7NmwcPNV/?ref=app

9th Jul 2018, 7:58 AM
Daniel Cooper
Daniel Cooper - avatar
18 Respuestas
+ 3
lol Thanks!
9th Jul 2018, 8:28 AM
Daniel Cooper
Daniel Cooper - avatar
+ 1
Erm. document.getElementById("textareaid").value += "\nNew Line";
9th Jul 2018, 8:02 AM
Andre Daniel
Andre Daniel - avatar
+ 1
Oh. I changed Para.innerHTML = document.getElementById("MyText").value; to Para.innerHTML = "<pre>" + document.getElementById("MyText").value + "</pre>" It works until you press find Es. The solution will be to remove the "<pre>" and "</pre>" tags from the p.innerHTML, then replace it. Let me see what I can do.
9th Jul 2018, 8:11 AM
Andre Daniel
Andre Daniel - avatar
+ 1
...I was mid paragraph explaining 😂😂😂 It works perfectly if we change p to pre 😅 Well, we both learn something new today!
9th Jul 2018, 8:27 AM
Andre Daniel
Andre Daniel - avatar
+ 1
No need to use pre Just add .replace(/\n/g, "<br\>"); to force the text with new lines. https://code.sololearn.com/WvduhrtFCNta/?ref=app
9th Jul 2018, 11:30 AM
Calviղ
Calviղ - avatar
+ 1
Yes..this works too. https://code.sololearn.com/WcS1n6coUZjY/?ref=app Note however, if you press the find buttin multiple times. the yellowness around the e gets larger. That's because you need to take out the span each time as well.
9th Jul 2018, 12:21 PM
Andre Daniel
Andre Daniel - avatar
+ 1
Well, you can use the replace to replace the spans. I'll see what I can do.
9th Jul 2018, 5:02 PM
Andre Daniel
Andre Daniel - avatar
+ 1
Remodified yet again. Just type away.
9th Jul 2018, 5:19 PM
Andre Daniel
Andre Daniel - avatar
9th Jul 2018, 5:22 PM
Andre Daniel
Andre Daniel - avatar
+ 1
And I fixed that too. xD I'm sure there is a better way, but for now here's this. Maybe Calviղ will come along and fix it I dunno.
9th Jul 2018, 5:23 PM
Andre Daniel
Andre Daniel - avatar
+ 1
It just occurred to me that we're using replace several times in the same line of code If I had known we could do that, I wouldn't have had a few of my problems xD
9th Jul 2018, 5:31 PM
Daniel Cooper
Daniel Cooper - avatar
0
I mean in the output of the code. I want MyPara to display the line breaks from MyText. Is this possible?
9th Jul 2018, 8:07 AM
Daniel Cooper
Daniel Cooper - avatar
0
https://code.sololearn.com/W45hTSA3zAqO/?ref=app Here's the code for editing. I'll see if I can figure anything out.
9th Jul 2018, 8:17 AM
Daniel Cooper
Daniel Cooper - avatar
0
Can you add comments to explain your changes? I'm new to coding and I want to understand rather than just imitate.
9th Jul 2018, 8:20 AM
Daniel Cooper
Daniel Cooper - avatar
0
wait
9th Jul 2018, 8:25 AM
Daniel Cooper
Daniel Cooper - avatar
0
I googled the HTML pre tag and why didn't we just replace the paragraph tag with the pre tag
9th Jul 2018, 8:25 AM
Daniel Cooper
Daniel Cooper - avatar
0
I actually wanted to find a way to make it only add 1 span, because I was hoping to have it instantly find the E's as you type, but I settled for a button because it kept adding spans.
9th Jul 2018, 4:51 PM
Daniel Cooper
Daniel Cooper - avatar
0
That makes it replace every e with a lowercase e again XD I have to go now. I'll try to figure it out after work.
9th Jul 2018, 5:22 PM
Daniel Cooper
Daniel Cooper - avatar