Hi everybody! I got stuck in a problem:
If I call a method of a self-defined object the "this" value usually equals to the self-defined object. However in the case of an event handling method I cannot get back the object. Can anyone help me?
If I call a method of a self-defined object the "this" value usually equals to the self-defined object. However in the case of an event handling method I cannot get back the object. Can anyone help me?
Code:
<html>
<head>
<script>
function Class1() {
this.choose = Choice;
this.Name;
}
function Choice(e) {
if (this.Name) alert(this.Name+" - Good!"); // this is what I want always
else if (this.tagName) alert(this.tagName+" :("); // but this is what I get when
// event is handled.
}
var Obj1 = new Class1();
Obj1.Name = "Object1";
</script>
<title>This</title>
</head>
<body onload="document.F1.S0.onchange=Obj1.choose">
<form method="GET" action="anything.cgi" name="F1">
<select size="2" name="S0">
<option>Option1</option>
<option>Option2</option>
</select>
</form>
<a href="javascript:Obj1.choose()">Obj.choose() - the nice case</a>
</body>
</html>