Click to See Complete Forum and Search --> : Please explain ..........


sudheeral
02-03-2003, 10:49 AM
:confused: Hi,
I have created javascript Object which handle some onclick events.
When the event handler is called it refers some variables correctly and some variables incorrecly.
I cannot undastand what is happening here.

Please explain to me why it is working/not working........


My Code :

<HTML>
<HEAD><TITLE>Testing</TITLE>
<style>
.myClass{
background-color:blue;height:100px;text-align:center;cursor:hand;
}
</style>
<script LANGUAGE="JavaScript">

function Test(myDiv){
this.value1 = "This is value 01";

myDiv.onclick=func1;

var myVar = "This is my var";

function func1(){
alert(myDiv.id); //working fine
alert(myVar); //working fine
alert(this.value1); //not working
}

}

//****************************************************
function windlow_onload(){
new Test(div1)
}

</script>
</HEAD>

<BODY onload=windlow_onload()>
<div id=div1 class=myClass>Click Here</div>
</BODY>
</HTML>


:mad:

khalidali63
02-03-2003, 10:56 AM
You are using "this" to reference a variable,which doesn't seem right in this context.
Get rid of it your code should give u desired results

cheers

Khalid

sudheeral
02-03-2003, 09:25 PM
Khalid,
Actually I want to know, what is this context & SCOPE of this context.

1)Why CANNOT refer object attributes
2)How CAN I able refer paramters and local variables.

Please explian to me...

thanks,