<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Building JavaScript</title>
<!---
** Originally based on an example by Shelley Powers, May 1997
** Modified for project use by Brian Smith, winter 2001
-->
<script language=JavaScript>
<!--- hide script from old browsers
// JavaScript Global Variables
sStatement = ""
sEndStatement = ""
msgTime = null
bQuoted = false
// JavaScript functions
// CallDialog
// call appropriate dialog to get
// extra information
function CallDialog(sStmt) {
var sDiag = ""
// check for stmt type
if (sStmt == "Color")
sDiag = "bkgnclor.html"
else if (sStmt == "Heading")
sDiag = "headdiag.html"
else if (sStmt == "Link")
sDiag = "linkdiag.html"
else
sDiag = "grphdiag.html"
newWindow=window.open(sDiag,"",
"toolbar=no,directories=no,width=500,height=400")
if (newWindow != null && newWindow.opener==null)
newWindow.opener=window
}
// create display window for document
//
// Open document and write to stream
function Evaluate(sExpression) {
parent.workFrame.document.open("text/html")
sExpression = "parent.workFrame." + sExpression
eval(sExpression)
parent.workFrame.document.close()
}
// BuildStmts
//
// function will access checkboxes and
// build JavaScript statments
// These will be sent to Evaluate
// for implementation
function BuildStmts(sStmt) {
// setup statment based on statement type
sStatement = "document.writeln"
if (sStmt == "Color") {
sStatement = sStatement +
"('<body bgcolor="
sEndStatement = ">')"
bQuoted=true
}
else if (sStmt == "Heading") {
sStatement = sStatement +
"('<h1> "
sEndStatement = "</h1>')"
}
else if (sStmt == "Link") {
sStatement = sStatement +
"('<a href="
sEndStatement = ">Link</a>')"
bQuoted=true
}
else {
sStatement = sStatement +
"('<img src="
sEndStatement = " width=200 height=200>')"
bQuoted=true
}
CallDialog(sStmt)
}
// FinishStmt
//
// function will finish building statement
// after return from information dialog
function FinishStmt(sValue) {
if (bQuoted) {
sStatement = sStatement + '"'
sEndStatement = '"' + sEndStatement
}
// add to existing statement and end stmt
sStatement = "parent.workFrame." + sStatement + sValue + sEndStatement
document.FormValue.Stmt.value=sStatement
}
!-->
</script>
<link rel="StyleSheet" href="info344.css" type="text/css">
</head>
<body>
<h3>Dynamic Building of JavaScript</h3>
<p>Select JavaScript statement you want to build from the radio buttons below.
You will be prompted for any additional information that might be needed. The
script you have created will print in the text area below the button, and the
JavaScript statement will be evaluated and results displayed in the frame window
below.</p>
<p>
<form name=FormValue>
<p><input name=Choice onclick=BuildStmts(this.value) type=radio
value=Color> Color <input name=Choice onclick=BuildStmts(this.value)
type=radio value=Heading> Heading <input name=Choice
onclick=BuildStmts(this.value) type=radio value=Image> Image <input
name=Choice onclick=BuildStmts(this.value) type=radio
value=Link> Link
<p>Statement: <BR><input name=Stmt size=70>
<p><input onclick=Evaluate(document.FormValue.Stmt.value) type=button value=Evaluate>
</form></p>
<p>The grade report and source code can be found <a href="js-grade.html">here</a>.
</body></html>