<HTML>
<HEAD>
<TITLE>An event of my own!</TITLE>
<SCRIPT>
function MyClass (name, text1, text2) {
this.name = name;
this.text1 = text1;
this.text2 = text2;
}
MyClass.prototype.toString = function () {
return this.name;
}
function on_Same () {
alert("The two values entered in " + this.toString() + " are the same!");
}
function check_Same() {
if (this.text1 == this.text2) {
this.onSame();
}
}
MyClass.prototype.checkSame = check_Same;
MyClass.prototype.onSame = on_Same;
function createMyClass (name, text1, text2) {
var x = new MyClass (name, text1, text2);
x.checkSame();
}
</SCRIPT>
</HEAD>
<BODY>
<TABLE>
<FORM>
<TR>
<TD>Name your object:</TD>
<TD>
<input type=text
name="txtName">
</TD>
</TR>
<TR>
<TD>Enter first text:</TD>
<TD>
<input type=text name="txtFirst">
</TD>
</TR>
<TR>
<TD>Enter second text:</TD>
<TD>
<input type=text
name="txtSecond">
</TD>
</TR>
<TR>
<TD>
</TD>
<TD>
<input type=button value="Do It!" onClick="createMyClass (txtName.value,txtFirst.value, txtSecond.value);">
</TD>
</TR>
</FORM>
</TABLE>
</BODY>
</HTML>
|