Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
carriage returned in text area
Old 12-01-2009, 08:01 AM carriage returned in text area
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Hi

Is itpossible to pick up all user input within a textarea including the carriage returns?

By example, i have a text area where the user is entering the address of a client.

I wish onBlur to write that information to another location on page including the carriage returned they have entered.

At current i am using a function to collect the value and write::

Code:
function setField(where, entered) {
	var update=document.getElementById(entered).value;
	document.getElementById(newpos).innerHTML=update;
}
However, this process doesnt include the carriage returns and just renders one string.

if this is possible any pointers would be appreciated.

cheers

Steve
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
 
Register now for full access!
Old 12-01-2009, 08:30 AM Re: carriage returned in text area
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
replace the carriage returns with "<br>"

Code:
update.replace('/n','<br>');
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-01-2009, 08:35 AM Re: carriage returned in text area
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
Thats what i did originally as below and it replaced the first one but not the following
ie input

line 1
line 2
line 3
line 4

result of js function =

line 1
line 2 line 3 line 4

Code:
function setField(where, entered) {	
     
	var update=document.getElementById(entered).value;
	
	var newUpdate = update.replace("\n", "<br/>");
	
	if (update.length>0) {
	document.getElementById(where).innerHTML=newUpdate;
	}
}
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 12-01-2009, 08:37 AM Re: carriage returned in text area
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
/n not \n

and add the global parameter to the regex

Code:
update.replace(/n/gi,'<br>');
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 12-01-2009 at 08:43 AM..
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-01-2009, 09:29 AM Re: carriage returned in text area
numbenator's Avatar
Webmaster Talker

Posts: 523
Location: London
Trades: 0
im obviously getting this wrong somewhere

So my js script will be

update.replace("/n/gi", "<br/>");

but this doesnt work at all?

Cheers for your help by the way
__________________

Please login or register to view this content. Registration is FREE
numbenator is offline
Reply With Quote
View Public Profile Visit numbenator's homepage!
 
Old 12-01-2009, 06:55 PM Re: carriage returned in text area
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
as it is all in special characters remove the quotes as in post #4
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to carriage returned in text area
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.76750 seconds with 12 queries