/    Sign up×
Community /Pin to ProfileBookmark

adding a <br> to text field on enter

i have a textfield for comments.
what i want is when the user hits the enter key i want to be able to append a
<br> to the text field or newline so when the form is submitted the comments are formatted as typed.( preferably the <br> wont be visible in the form field but i could live with it )

its on an intranet and the only browser used is ie v6.

what its for is the form will generate an email ( from a template )
and i want the comment to appear as typed in the form field.

any ideas?

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@KorJun 16.2005 — 
preferably the <br> wont be visible in the form field but i could live with it
[/quote]

If so, try this for a start:
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function insBr(e,t){
var key=(typeof event!='undefined')?window.event.keyCode:e.keyCode;
if(key==13){
t.value=t.value+'<br>';
}
}
function showT(){
document.getElementById('txt').innerHTML = document.forms[0].elements['txta'].value;
}
</script>
</head>
<body>
<form>
<textarea name="txta" cols="" rows="" onkeyup="insBr(event,this)"></textarea><br>
<br>
<div id="txt"></div><br>
<br>
<input name="" type="button" value="showtxt" onclick="showT()">
</form>

</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@andyshepauthorJun 16.2005 — cheers Kor,

thats a great start for me thx again.
Copy linkTweet thisAlerts:
@BigMoosieJun 16.2005 — This is something that should be done on the server, in PHP it would be:

[code=php]
$message = str_replace("n", "<BR>", $message);[/code]
Copy linkTweet thisAlerts:
@andyshepauthorJun 16.2005 — This is something that should be done on the server[/QUOTE]

that would be presuming the server supported php.

since it doesnt im limited
Copy linkTweet thisAlerts:
@BigMoosieJun 16.2005 — Pehaps the solution would be to enclose the message in a <PRE> tag.
Copy linkTweet thisAlerts:
@andyshepauthorJun 16.2005 — hi again.

ok ive got the form working now and it generates the email with the header / footer/ text etc.

but when i send the page it doenst send the generated page it sends the form used to generate the page.

are there any work arounds for this?

or is php the only way to go for this?
Copy linkTweet thisAlerts:
@BigMoosieJun 16.2005 — If you view your email in plain text rather than HTML it should have the line breaks, see if that is an option in your mail client.
×

Success!

Help @andyshep 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...