views:

64

answers:

1

I am passing value of text-area in a.cfm in variable of GetXmlHttpObject to b.cfm page and displaying the value in a . How can I get exact formatting of the text I entered in text-area of a.cfm page into div of b.cfm page.

a.cfm
    <textarea name="sum1#i#" id="sum1#i#" html="yes" cols="98" rows="5"></textarea> [my text area]
    url=url+"?dept="+iden+"&desc="+encodeURIComponent(desc); [desc: value of text area]

b.cfm
    <cfoutput>
    <div style="border:1px solid">#URLDecode(desc)#</div>   
    </cfoutput>

Like I am sending value as 'hellothere' encodeURIComponent: 'hello%0Athere'

but its appearing as 'hello there' [in one line] I want it to be in: 'hello <break-line> there' [in two different lines, means in the same format as it was in text-area]

Thanks!!!

+4  A: 

The <pre></pre> tags will preserve spaces and newlines.

<cfoutput>
    <div style="border:1px solid"> <pre>#URLDecode(desc)#</pre> </div>   
</cfoutput>
Ryan Zachry
Thanks Ryan that worked!!
Deepak Yadav
You'll want to be extremely careful, as doing this could open your site up for XSS and possibly other security attacks. (An attacker could send someone to `b.cfm?desc=</textarea><script type='text/javascript'>function submitUserPasswordToMySite(){...}; submitUserPasswordToMySite();</script>` and it would have access to local data and be able to send data to an external location that would log it.) As a general rule, never directly render something from the URL on the page without *cleaning* it first. By cleaning, of course, I mean removing potential security threats.
Adam Tuttle
Thanks for the suggestion Adam.
Deepak Yadav