Retrieve the value in TextArea with the newline preserved.

C

chin

Hi,
I am trying to retrieved the value of the textarea with the newline
preserved without having to submit the form to the server. Does anyone
knows how to? I tried soft and hard wrap but both does not seems to
affect the input in anyway.

Example :
<form name=frm>
<textarea name=ta wrap="soft"></textarea>
</form>
<script language=javascript>
alert(document.frm.ta.value) // <-- the alerted value should look
exactly as what is entered in the textbox.
</script>

regards,
Chin
 
M

McKirahan

chin said:
Hi,
I am trying to retrieved the value of the textarea with the newline
preserved without having to submit the form to the server. Does anyone
knows how to? I tried soft and hard wrap but both does not seems to
affect the input in anyway.

Example :
<form name=frm>
<textarea name=ta wrap="soft"></textarea>
</form>
<script language=javascript>
alert(document.frm.ta.value) // <-- the alerted value should look
exactly as what is entered in the textbox.
</script>

regards,
Chin

This works for me.

<html>
<head>
<title>textline.htm</title>
<script type="text/javascript">
function text() {
alert(document.frm.ta.value)
}
</script>
</head>
<body>
<form name=frm>
<textarea name="ta" wrap="soft" cols="80" rows="10">
the alerted value

should look exactly as what is entered in the textbox.
</textarea>
<input type="button" value="text()" onclick="text()")
</form>
</body>
</html>

The only problem I see is when the textarea causes words to a new line
because of line overflow; this is not the same as a newline.
 
C

chin

Thanks. Your example work because you have entered a hard carriage
return. What I need is, when the text in the textbox automatically
wrapped because of the cols value, I would be able to retrieve the
text as what the user sees in the text box. The example below the user
did NOT do a carriage return between "long" and "string" when the
information is typed into the textbox.
 
M

McKirahan

chin said:
Thanks. Your example work because you have entered a hard carriage
return. What I need is, when the text in the textbox automatically
wrapped because of the cols value, I would be able to retrieve the
text as what the user sees in the text box. The example below the user
did NOT do a carriage return between "long" and "string" when the
information is typed into the textbox.

Good luck! Perhaps if you used a fixed spaced font such as Courier (set via
CSS) you might be able to calculate were each row breaks.
 
F

Fred Oz

chin said:
Thanks. Your example work because you have entered a hard carriage
return. What I need is, when the text in the textbox automatically
wrapped because of the cols value, I would be able to retrieve the
text as what the user sees in the text box. The example below the user
did NOT do a carriage return between "long" and "string" when the
information is typed into the textbox.

Try adding wrap="physical" to your textarea. It is not supported by all
browsers, but it will put breaks in the text string where the browser
breaks the lines, you can see it in the submit string as %0D%0A.

Have fun - Fred.
 
C

chin

Try adding wrap="physical" to your textarea. It is not supported by all
browsers, but it will put breaks in the text string where the browser
breaks the lines, you can see it in the submit string as %0D%0A.

Have fun - Fred.
Thanks Fred.

Unfortunately, my problem is that I need the line break without having
to submit the page to server. It seems that I do not have much choice
but to calculate the number word in the line and put the line break
myself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top