473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

img.onclick=function{this.attribute=2}

obj=function()
{
this.attribute=1
this.method=function()
{
img=document.createElement('img')
img.onclick=function
{
this.attribute=2 // i need the obj this not the img this :)
}
document.body.appendChild(img)
}
}
obj1=new obj()
obj1.method()

Anybody know how to set the obj1 atribute by clicking on a the image ?

Mar 21 '07 #1
2 2241
Try the following:

obj=function()
{
var me = this;
this.attribute=1;
this.method=function()
{
var img=document.createElement('img');
img.src="testimage.gif";
img.onclick=function ()
{
me.attribute=2;
}
document.body.appendChild(img);
}
}

Note that, when the object is created, I store a reference to the
object in a variable called "me". I can then use "me" later on to
refer to the original object, in contexts in which "this" refers to
something else.

I hope that makes sense.

wp.

Mar 21 '07 #2
On Mar 21, 2:40 pm, "wisestpotato" <wisestpot...@googlemail.com>
wrote:
Try the following:

obj=function()
{
var me = this;
this.attribute=1;
this.method=function()
{
var img=document.createElement('img');
img.src="testimage.gif";
img.onclick=function ()
{
me.attribute=2;
}
document.body.appendChild(img);
}

}

Note that, when the object is created, I store a reference to the
object in a variable called "me". I can then use "me" later on to
refer to the original object, in contexts in which "this" refers to
something else.

I hope that makes sense.

wp.
great thx :)

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jdub | last post by:
I bringing up a list of movies in a separate window where each one has an "onclick" function which is suppose to call a procedure and pass in the variables and display the details of the selected...
1
by: chanko | last post by:
Hello all, i'm having a little problem while adding script blocks from my codebehind i have a page that registers a new product in my database, and upon finishing, this page should open a popup...
5
by: Michel | last post by:
Hi Group of helpers, Following snippet of code: <HTML> <HEAD> <script> function color(value) { alert(value);
4
by: jj6849 | last post by:
I have been using the dom to add a row to my form for awhile now, but now I need to do some validation to make sure certain check boxes aren't checked with other check boxes. Now of course it works...
1
by: quickcur | last post by:
Hi, here is my code: <html> <head> <script type="text/javascript"> function setImage(num) { alert(num); }
4
by: manu3d | last post by:
Hi everybody, I'm generating some DIVs dinamically, inclusive of an event function to run when the user clicks on them. While the following lines work perfectly in FF 1.5, I.E. 6.0 ignores...
1
by: Mike Scirocco | last post by:
I use this function to detect an iframe button click. It works in IE6 but not in FF 1.5. function setupbutton(){ var myiframe=document.getElementById('ifrmEditCategory'); var...
3
by: msinghal | last post by:
hi, I am facing one problem which is related to AJAX. I have a html page which has some links. When the page is refreshed using AJAX then if some new new link is added to the page on this refresh,...
4
by: 1965 | last post by:
Hi,All. I want to click a string, then pass the string to asp file, where I use function to get a remote xml file, and then use brower to parse this xml file. But it doe not work. Is the code right?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.