/    Sign up×
Community /Pin to ProfileBookmark

TextArea tags and JavaScript

I have on my website two textareas for people to write notes. one of the textareas is small and then you can click an enlarge button and a much larger textarea would pop up in a div tag.

If you type your notes in this larger textarea and have carriage returns in the textarea when you close the div/textarea i take the value out of that textarea and put it into the smaller textarea. it loses all the carriage returns when it goes into that smaller textarea.

I have read online that what is happening is when a user types a carriage return it is then ignored by html so if you do a replace on the vbCrLf with <BR> then that will fix the problem. However they were all doing this after the form was submitted and doing a replace with VBScript.

I however am not submitting the form yet its all handled with javascript. I replaced the vbCrLf with <BR> tags in javascript but doesn’t seem to be working.

[CODE]
NotesValue = document.getElementById(theNumber2).value;
NotesTemp = (NotesValue.replace(/vbCrLf/gi, “<BR>”));
NotesValue = NotesTemp;

document.getElementById(theNumber).innerHTML = NotesValue;
[/CODE]

any ideas would be greatly appreciated

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@mrhooApr 27.2007 — This sounds overly complicated- why not just resize the textarea?
Copy linkTweet thisAlerts:
@pricejtauthorApr 27.2007 — Because thats not the way i want to do it :-)
Copy linkTweet thisAlerts:
@AshfordApr 27.2007 — This might help you find your way.

var text = document.myFormName.abc_text.value;

// Retain engraving text line breaks for html

var text_with_breaks = text.replace(/(rn|r|n)/g, '<br>');
Copy linkTweet thisAlerts:
@pricejtauthorApr 28.2007 — Sorry it has been so long I am actually away this weekend traveling i just got a chance to try out your solution.

This is what i put in the code

[CODE] NotesValue = document.getElementById(theNumber2).value;
var text_with_breaks = NotesValue.replace(/(rn|r|n)/g, '<br>');
NotesValue = text_with_breaks;

document.getElementById(theNumber).innerHTML = NotesValue;[/CODE]


Unfortuantly when i run this it thorws a javascript runtime error when it tries putting it back into the smaller textarea. (the last line of code here)
Copy linkTweet thisAlerts:
@kewOct 12.2009 — I've been searcing around for hours looking for the answer to this very question, and this is the first time I've found a simple, unconfusing answer that works!

Thank you so much.
×

Success!

Help @pricejt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...