Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextArea value property question

Status
Not open for further replies.

nazzaro

Programmer
Jun 28, 2000
31
US
I'm using an asp to fill a textarea html element "dynamically", that is, I'm filling it as the server completes calculations so the user can follow the progress (I use response.flush to send Javascript to the client periodically to update the 'value' property of the textarea).

Problem is, I can't seem to add line feeds to show information on separate lines. In Html, if the info is on separate lines, it shows on separate lines in the TextArea element, i.e.:

<Textarea>
line one
line two
</Textarea>

But when I try to 'append' a line feed, carriage return or both to the 'value' property of the TextArea element, it shows up as a 'box' character instead of being recognized as a line feed.

Any suggestions (other than building the entire contents of the TextArea element on the server before sending - that would defeat the purpose of the technique)

For now, I'm padding with spaces so things 'wrap' properly, but there's got to be a better way. If I ever wanted to let the client print the contents of the TextArea, I'd have to do all the line breaks in code.

Here's some test code (just to illustrate the technique):

<% @enablesessionstate=false %>
<% response.buffer=true %>

<%
response.write &quot;<html>&quot;
response.write &quot;<head>&quot;
response.write vbcrlf + &quot;<Script Language='JavaScript'>&quot; + vbcrlf
response.write &quot;<!--&quot; + vbcrlf
response.write &quot;function ProcessContent(Content){&quot; + vbcrlf
'response.write &quot;alert(Content);&quot; + vbcrlf
'response.write &quot;select1.options.length=select1.options.length + 1;&quot;
'response.write &quot;select1.options[select1.options.length - 1].text=Content;&quot; + vbcrlf
response.write &quot;select1.value=select1.value+Content+vbcrlf;&quot; + vbcrlf
response.write &quot;}&quot; + vbcrlf
response.write &quot;-->&quot; + vbcrlf
response.write &quot;</Script>&quot; + vbcrlf
response.write &quot;</head>&quot;
line=&quot;<body onload=&quot; + chr(34) + &quot;alert('Body Loaded')&quot; + chr(34) + &quot;>&quot;
response.write line
'response.write &quot;<Select size=10 id='select1' multiple='true'><Option>This is the first option. Does it display?</Option></Select>&quot;
response.write &quot;<TextArea readonly rows=20 cols=60 id='select1'>This is the first option. Does it display?&quot; + chr(10) + &quot;</TextArea>&quot;
line=&quot;<DIV id='Div1'>This is the first Div1</DIV>&quot;
response.write line
response.flush
response.write &quot;<Table id='Table1' border=1 cellspacing=0 cellpadding=0 bgColor='White'>&quot;
for i=1 to 100
response.write &quot;<td border=0 bordercolor=white>&nbsp;</td>&quot;
next
response.write &quot;</Table>&quot;
response.flush
'line=&quot;<img style='display:none' onerror='ProcessContent(this.alt)' alt='This is the content to be sent' src='blah'>&quot;
'response.write line
'response.flush
'line=&quot;<img style='display:none' onerror='ProcessContent(this.alt)' alt='This is more content to be sent' src='blah'>&quot;
'response.write line
'response.flush
for i=1 to 1000
Content=&quot;This is content line &quot; & i
for l=1 to (60-len(Content))
Content=Content+&quot; &quot;
next
Progress=int(i/10)
if Progress>99 then
Progress=99
end if
' Progress=20
response.write vbcrlf + &quot;<Script Language='Javascript'>&quot; + vbcrlf
response.write &quot;<!--&quot; + vbcrlf
response.write &quot;Content='&quot; & Content & &quot;';&quot; + vbcrlf
' response.write &quot;select1.options.length=select1.options.length + 1;&quot; + vbcrlf
' response.write &quot;select1.options[select1.options.length - 1].text=Content;&quot; + vbcrlf
' response.write &quot;select1.options[select1.options.length - 1].selected=true;&quot; + vbcrlf
' response.write &quot;select1.options[select1.options.length - 1].selected=false;&quot; + vbcrlf
response.write &quot;select1.value=select1.value + Content;&quot; + vbcrlf
response.write &quot;select1.scrollTop=select1.scrollHeight;&quot; + vbcrlf
response.write &quot;for (var k=0; k<&quot; & (Progress+1) & &quot;; k++)&quot; + vbcrlf
response.write &quot;{&quot; + vbcrlf
response.write &quot;Table1.rows[0].children[k].bgColor='Blue';&quot; + vbcrlf
response.write &quot;Table1.rows[0].children[k].borderColor='Blue';&quot; + vbcrlf
response.write &quot;}&quot; + vbcrlf
response.write &quot;-->&quot; + vbcrlf
response.write &quot;</Script>&quot;
response.flush
if response.isclientconnected=false then
response.end
end if
' if i=100 then
' while response.isclientconnected<>false
' wend
' response.end
' end if
' for j=0 to 1000
' next
next
response.write &quot;</body>&quot;
response.write &quot;</html>&quot;
response.flush
%>

 
Tha answer was to add:

unescape('%0D') to each line rather than:
unescape('%13') which is what I tried.

Oh well, I've done dumber things before. [sig][/sig]
 
I would do an ASP search and replace of all the line feed characters in whatever you're sticking into the textbox and make sure that they're replaced with a character that it recognizes.

Where are you getting the text from? [sig]<p> <br><a href=mailto:aberman@thebiz.net>aberman@thebiz.net</a><br><a href= > </a><br>Database web programmer and developer, fueled by peach snapple and mochas.[/sig]
 
Thanks for the help,

I discovered the problem (see my response to myself above).

The code is just an example. A real application would send the results of a calculation or check, along with a % complete status.

I've optimized the code quite a bit from the example. I now use a function in the HEAD of the document to do the actual updating, then I periodically send just the code needed to call the function, passing the content and status info. That code is &quot;wrapped&quot; in a DIV with id=&quot;tempStuff&quot;. The last thing the function does is execute tempStuff.removeNode so, in the end, no additional code appears in the document itself. [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top