• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

19. Scripting > 19.2. Writing Output

Writing Output

You can’t directly output text or variable values to the browser within a cfscript block. There is, however a function called WriteOutput( ) that you can use to write directly to the page output stream. This technique can output both variable values and plain text from within a cfscript block. Example 19-1 demonstrates the WriteOutput( ) function.

Example 19-1. Using the WriteOutput( ) function within a cfscript block
<h2>Using WriteOutput Within cfscript</h2>
   
<cfscript>
 x = 1;
 y = 2;
 MyMessage = "Hello World";
 
 WriteOutput("x = #x# <br>");
 WriteOutput("MyMessage = #MyMessage# <br>");
 WriteOutput(x+y); 
</cfscript>

In this case, because there is no way to embed HTML directly within the cfscript block, all formatting is done by embedding the HTML code within the WriteOutput( ) function. Executing Example 19-1 results in the output shown in Figure 19-1.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint