Listing 1: resolveZip.jsp

<%@ page info="resolveZip" %>
<%@page import="java.util.Properties"%>

<%
	String lookupType = request.getParameter("lookupType");

	Properties properties = (Properties)getServletContext().getAttribute(lookupType);

	if (properties == null)
	{
		properties = new Properties();
		try {
        		properties.load(new java.io.FileInputStream("c:\\" + lookupType + ".property"));
			getServletContext().setAttribute(key, properties);
		} catch (java.io.IOException e) {
			out.println("Property File not found");
		}
	}
	out.println(properties.getProperty(request.getParameter("zip")));
%>

Listing 2: zipsearch.html (IFRAME)

Zip:<input  id="zipcode" type="text" maxlength="5"  onKeyUp="zipchanged()" style="width:60" size="20"/>
City: <input id="city" disabled maxlength="32" style="width:160" size="20"/>
State:<input id="state" disabled maxlength="2" style="width:30" size="20"/>
<iframe id="controller" style="visibility:hidden;width:0;height:0"></iframe>

<script src="iframe.js"></script>
<script>
var zipField = null;
function zipchanged(){
	zipField = document.getElementById("zipcode")
	var zip = zipField.value;
	zip.length == 3?updateState(zip):zip.length == 5?updateCity(zip):"";

}
function updateState(zip) {
	var stateField = document.getElementById("state");
	ask("resolveZip.jsp?lookupType=state&zip="+zip, stateField, zipField);
}
function updateCity(zip) {
	var cityField = document.getElementById("city");
	ask("resolveZip.jsp?lookupType=city&zip="+zip, cityField, zipField);
}
</script>

Listing 3: iframe.js

function response(result, fieldToFill, lookupField)
{
	var lookup = document.getElementById(lookupField);
	var fill = document.getElementById(fieldToFill);

	if ( result == "null" ) {
		lookup.style.borderColor = "red";
		fill.value = "";
	} else {
		lookup.style.borderColor = "";
		fill.value = result;
	}
}

function ask(url, fieldToFill, lookupField)
{
	var controller = document.getElementById("controller");
	controller.src = url+"&field="+fieldToFill.id+"&lookup="+lookupField.id;
}

Listing 4: resolveZip.jsp (IFRAME)

<%@ page info="resolveZip" %>
<%@page import="java.util.Properties"%>

<script>
<%
	String lookupType = request.getParameter("lookupType");

	Properties properties = (Properties)getServletContext().getAttribute(lookupType);

	if (properties == null)
	{
		properties = new Properties();
		try {
        		properties.load(new java.io.FileInputStream("c:\\" + lookupType + ".property"));
			getServletContext().setAttribute(key, properties);
		} catch (java.io.IOException e) {
			out.println("Property File not found");
		}
	}

	out.println("var field= '" + request.getParameter("field") +"'");
	out.println("var lookup= '" + request.getParameter("zip") +"'");
	out.println("var result= '" + properties.getProperty(request.getParameter("zip")) +"'");
%>
	window.top.window.response(result, field, lookup);
</script>

Listing 5

// Constructor
function Calculator(ops) {
    	this.ops = ops;
}
with (Calculator) {
	// Make constructor available as a member function
	prototype.Calculator = Calculator;
	// Member functions
	prototype.evaluate = function () {
		this.opsStack = new Array();
		for (var i = 0; i < this.ops.length; i++) {
			var op = this.ops[i];
			if (typeof op == "number")
				this.push(op);
			else if (typeof this[op] == "function")
				this[op]();
		}
		return this.pop();
	};
	prototype.pop = function () {return this.opsStack.pop();}
	prototype.push = function (val) {this.opsStack.push(val);}
}

//Constructor
function ArithmeticCalcuator(ops) {
	this.Calculator(ops);	// super
};
with (ArithmeticCalcuator) {
	// Establish inheritance
	ArithmeticCalcuator.prototype = new Calculator();
	prototype.constructor = ArithmeticCalcuator;
	// Make constructor available as a member function
	prototype.ArithmeticCalcuator = ArithmeticCalcuator;
	// Member functions
	prototype.add = function () {this.push(this.pop() + this.pop()); }
	prototype.sub = function () {this.push(this.pop() - this.pop());}
	prototype.mul = function () {this.push(this.pop() * this.pop());}
	prototype.div = function () {this.push(this.pop() / this.pop());}	
}

Listing 6

<PUBLIC:COMPONENT NAME="cbx" tagName="CHECKBOX">
<PROPERTY NAME="label" />
<PROPERTY NAME="checked" GET="getChecked" PUT="putChecked" />
<PROPERTY NAME="labelonleft" VALUE="true"/>
<PROPERTY NAME="value" GET="getValue" PUT="putValue" />
<PROPERTY NAME="onValue" VALUE="true"/>
<PROPERTY NAME="offValue" VALUE="false"/>
<METHOD NAME="show"/>
<EVENT NAME="onItemChanging" ID="onItemChanging"/>
<EVENT NAME="onItemChanged" ID="onItemChanged" />
<ATTACH EVENT="oncontentready" HANDLER="constructor" />
<SCRIPT >

	var _value;

	function constructor() 	{
		var s;
		s = '<INPUT name="cb_'+ uniqueID + '" id="cb_' + uniqueID + '" type="checkbox" ' +
			'onclick="' + uniqueID + '.checked= +cb_' + uniqueID+ '.checked" ';
		if( _value == onValue ) 
			s +=' checked="true" ';
		s+= "/>";
		element.insertAdjacentHTML('afterBegin', s);
		element.insertAdjacentHTML((labelonleft == "true")?'afterBegin':'beforeEnd', 
			'<LABEL for="cb_' + uniqueID+ '">' + label + '</LABEL>');
	}

	function putChecked( newValue ) {
		value = (newValue?onValue:offValue);
	}
	function getChecked(){
		return ( _value == onValue);
	}

	function getValue(){
		return _value ;
	}
	function putValue( newValue ) {
		if (window.event == null)
			_value = newValue; /* initial*/
		else if (_value != newValue) {
			var oEvent = createEventObject();
			oEvent.newValue = newValue;
			oEvent.returnValue = true;
			onItemChanging.fire(oEvent);
			if (oEvent.returnValue)
				_value = newValue;
			eval('cb_'+uniqueID).checked= ( _value == onValue );
			if (_value == newValue)
				onItemChanged.fire(oEvent);
		}
	}

	function show(bCmdShow){
		style.visibility= (bCmdShow?'visible':'hidden') ;
	}

</SCRIPT>
</PUBLIC:COMPONENT>