Showing message box using cfscript.
Used JavaScript inside the cfscript block.
The main scenario came into picture where the script has to be dynamically generated and written on the page which would use the value in a server side variable. The main implementation was to use the session variable value to do the check. Here in this example, a alert box is implemented.
ColdFusion does not have cfscript syntax to display a message. We have to use javascript to do the same. Let us consider the following snippet which is a classic CF check to display a message.,
Snippet #1
This can be implemented by the following approach in cfscript.,
<html>
<head>
<title>.:: WriteOutput - alert ::.</title>
<cfif isdefined('btnSubmit')>
<script language="javascript" type="text/javascript">
alert('Page posted to the Server');
</script>
</cfif>
</head>
<body>
<cfform id="SampleForm" name="SampleForm" method="post">
<input type="submit" id="btnSubmit"
name="btnSubmit"
value="Click to Post the Page"/>
</cfform>
</body>
</html>
Snippet #2
<html>
<head>
<title>.:: WriteOutput - alert ::.</title>
<cfscript>
if(isdefined('btnSubmit'))
{
writeoutput("<script language='javascript'
type='text/javascript'>
alert('Page posted to the Server');
</script>");
}
</cfscript>
</head>
<body>
<cfform id="SampleForm" name="SampleForm" method="post">
<input type="submit" id="btnSubmit"
name="btnSubmit"
value="Click to Post the Page"/>
</cfform>
</body>
</html>
+