To create the enable/disable function (p. 428, Step 2)
<!DOCTYPE HTML SYSTEM "-//Macromedia//DWExtension layout-engine 5.0//dialog">
<HTML>
<HEAD>
<TITLE>Make Lower Case</TITLE>
<SCRIPT LANGUAGE="javascript">
Script 19.1 (p. 428)
function canAcceptCommand() {
var theDOM = dw.getDocumentDOM();
if (theDOM == null) return false;
var theSel = theDOM.getSelection();
var theSelNode = theDOM.getSelectedNode();
var theChildren = theSelNode.childNodes;
return (theSel[0] != theSel[1] && ((theSelNode.nodeType == Node.TEXT_NODE) || (theChildren[0] != null && theChildren[0].nodeType == Node.TEXT_NODE))); }
Script 19.2 (p. 430)
function changeToLowerCase() {
var theDOM = dw.getDocumentDOM();
var theSel = theDOM.getSelection();
var theDocEl = theDOM.documentElement;
var theWholeDoc = theDocEl.outerHTML;
var selText = theWholeDoc.substring(theSel[0],theSel[1]);
theDocEl.outerHTML = theWholeDoc.substring(0,theSel[0]) + selText.toLowerCase() + theWholeDoc.substring(theSel[1]); theDom.setSelection(theSel[0],theSel[1]);
}
To finish up the file (p. 431)
</SCRIPT>
</HEAD>
<BODY onLoad="changeToLowerCase()">
</BODY>
</HTML>
To add the command to the menu (p. 433, Step 6)
<menuitem name="Make _Lower Case" file="Menus/MM/Make_Lower_Case.htm" id="VQP_Make_Lower_Case" />
Script 19.3 (p. 435)
<?xml version="1.0"?>
<!DOCTYPE toolbarset SYSTEM "-//Macromedia//DWExtension toolbar 5.0">
<toolbarset>
<toolbar id="VQP_toolbar" label="VQP">
<button id="VQP_Make_Lower" image="Toolbars/Images/vqp/lower.gif" DisabledImage="Toolbars/Images/vqp/lower_dis.gif" update="onSelChange" tooltip="Make Lower Case" file="Menus/MM/make_lower_case.htm" /> </toolbar>
</toolbarset>
To create the Confirm Password behavior (p. 437-441)
Step 3.
<!DOCTYPE HTML SYSTEM "-//Macromedia//DWExtension layout-engine 5.0//dialog"> <html>
<head>
<title>Confirm Password</title>
<meta http-equiv="Content-Type" content="text/html">
and Step 4.
<SCRIPT SRC="../../Shared/Common/Scripts/ListControlClass.js">
</SCRIPT>
and Step 5.
<script language="JavaScript">
var theMenu;
and Step 6.
function compareFields(field1,field2) {
if (field1.value != field2.value) {
alert("Your password does not match your confirmation");
field2.value = "";
field2.setFocus();
}
}
and Step 7. (p. 437)
function canAcceptBehavior()
{
var theDOM = dw.getDocumentDOM();
var selObj = theDOM.getSelectedNode();
if (selObj.nodeType == Node.ELEMENT_NODE && selObj.tagName == "INPUT" && selObj.getAttribute("type").toUpperCase() == "PASSWORD" ) return "onBlur";
return false;
}
and Step 8. (p. 439)
function behaviorFunction()
{
return "compareFields";
}
and Step 9.
function applyBehavior()
{
var theDOM = dw.getDocumentDOM();
var firstField = theMenu.getValue();
var secondField = dw.getElementRef("NS 4.0", theDOM.getSelectedNode());
return "compareFields("+firstField+", "+secondField+")";
}
Script 19.4 (p. 440)
function populateMenu()
{
theMenu = newListControl("firstestField");
var theDOM = dw.getDocumentDOM();
var selObj = theDOM.getSelectedNode();
var theForm = selObj.parentNode;
var allElements = theForm.childNodes;
var i, tmp;
var passList = new Array ();
for (i=0;i<allElements.length;i++)
{
tmp = allElements.item(i)
if (tmp.nodeType == Node.ELEMENT_TYPE && tmp.tagName == "INPUT" && tmp.getAttribute("type").toUpperCase() == "PASSWORD" ) passList.push(dw.getElementRef("NS 4.0", tmp));
}
for (i=0;i<passList.length;i++) {
tStr = passList[i].toString().split(".");
uStr = tStr[tStr.length - 1];
theMenu.append(uStr, passList[i].toString());
}
}
and Step 11. (p. 441)
</script>
</head>
<body>
Please select the field to confirm the field against.
<form name="theForm" method="post" action="">
<select name="firstestField" id="firstestField" onFocus="populateMenu()">
<option value="x">**no password fields**</option>
</select>
</form>
</body>