Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 23rd, 2009, 12:18 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
AddEventListener

Hey guys, I don't like it when this happens, you have a piece of code, it works perfectly, you copy it over and it stops working lol.

I'm trying to change the onclick event of an element, and it is not. It works fine with a button, however with the TD tag which is what I am trying to apply it to does not work.

Code:
//orig code
	var t = document.getElementById("setbut");
	t.value = "Set Pieces";
    	t.onclick=null;
	if (window.addEventListener) { 	// Mozilla, Netscape, Firefox
		t.addEventListener('click', startGame, false);
	}
	else {	// IE
		t.attachEvent('onClick', startGame);
	}

//end of orig

//now I move this code into a loop for the cells I need changing

//new code
			t = document.getElementById(i+tmpA[bn]+ii);
			t.onclick=null;
			if (window.addEventListener) {	// Mozilla, Netscape, Firefox
				t.addEventListener('click', bombard, false);
				if(i==10 && ii==10) alert(t.click); ;
			}	
			else {
				img.attachEvent('onClick', bombard);
			}

//end new code


Now I know the right parti is being called, due to the alert in the first if statement, however it just shows "undefined". So can I not use this to change the onclick of a td?
__________________
~~==~~ Whoever said nothing is impossible never tried pushing a revolving door ~~==~~

Reply With Quote
  #2  
Old March 23rd, 2009, 12:22 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
Oh, never mind, it is working, I was just expecting the change to show in firebug aswell

Reply With Quote
  #3  
Old March 23rd, 2009, 12:26 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
haha. I would have suggested to wrap the tag with the <a> tag (sorta like applying CSS onmouseover & onmouseout to a form button)... but nevermind
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge.

Reply With Quote
  #4  
Old March 23rd, 2009, 12:38 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
actually using this how would I tell it to use variables?

I tried t.addEventListener('click', bombard(this.id), false);

But that doesnt work

Reply With Quote
  #5  
Old March 23rd, 2009, 12:46 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
if you use 'this' what does it use? I thought 'this' meant the current element doesn't matter what the ID or Name is.... but not sure.

Reply With Quote
  #6  
Old March 23rd, 2009, 12:49 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
Well to start with the td is like this

<td id="1-1" onclick="thiscell(this.id)">

but then I click the link I need it to go to

<td id="1-1" onclick="bombard(this.id)">

So that the id of the clicked cell is available to the bombard function.

Reply With Quote
  #7  
Old March 23rd, 2009, 01:00 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
I know you are better at JS/DOM than I am, but I will try to help the best I can. Not sure if my suggestions will be useful or not.

Can you post your bombard function?

If it's like:

function bombard(x) {

}

try to add:

alert(x);

to the top of it to see what is being passed to the function.

Reply With Quote
  #8  
Old March 23rd, 2009, 01:44 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
I get "undefined" if I do that.

Reply With Quote
  #9  
Old March 23rd, 2009, 02:02 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
So in your single element you have both?:
onclick="thiscell(this.id); bombard(this.id);"

and only 'thiscell()' works (correctly)?

Reply With Quote
  #10  
Old March 23rd, 2009, 02:11 PM
Osiris Osiris is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: May 2008
Location: Sussex
Posts: 566 Osiris User rank is Private First Class (20 - 50 Reputation Level)Osiris User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 19 h 54 m 33 sec
Reputation Power: 2
no, when the page is loaded the element has an onclick="thiscell(this.id)"

But after a function is called I need it to change to

onclick="bombard(this.id)"

Reply With Quote
  #11  
Old March 23rd, 2009, 02:31 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
In your bombard function set you element (x as I've referred to it previously) to this.id and erase the x from:
function bombard(x) {

}

so it becomes

PHP Code:
function bombard() {

var 
document.getElementById(this.id);

//also alert out the id
alert(this.id);




What do you get with that? -- this isn't going to work, ignore this post...

Last edited by jamestrowbridge : March 23rd, 2009 at 02:45 PM. Reason: nevermind

Reply With Quote
  #12  
Old March 23rd, 2009, 02:55 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
In your first post, should:
img.attachEvent('onClick', bombard);

be:
t.attachEvent('onClick', bombard);

Reply With Quote
  #13  
Old March 23rd, 2009, 03:12 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
Have a look here: This seems like that issue you are having, possibly solved? http://www.captain.at/howto-addeven...-parameters.php

Reply With Quote
  #14  
Old March 23rd, 2009, 03:30 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
Forget that crap I just posted, give me 5 min.

Reply With Quote
  #15  
Old March 23rd, 2009, 03:48 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 411 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 18 h 54 m 24 sec
Reputation Power: 2
This will only fix it for everything besides IE - I'm still working on it though (EDIT: SEE PAGE 2)
Code:
//orig code
	var t = document.getElementById("setbut");
	t.value = "Set Pieces";
    	t.onclick=null;
	if (window.addEventListener) { 	// Mozilla, Netscape, Firefox
		t.addEventListener('click', startGame, false);
	}
	else {	// IE
		t.attachEvent('onClick', startGame);
	}

//end of orig

//now I move this code into a loop for the cells I need changing

//new code
			t = document.getElementById(i+tmpA[bn]+ii);
			t.onclick=null;
			if (window.addEventListener) {	// Mozilla, Netscape, Firefox
//changed some stuff in the line below:
				t.addEventListener('click', function() { bombard(i+tmpA[bn]+ii); }, false);
				if(i==10 && ii==10) alert(t.click); ;
			}	
			else {
                                                   img.attachEvent('onClick', bombard);
			}

//end new code

Last edited by jamestrowbridge : March 23rd, 2009 at 04:52 PM.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > AddEventListener


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek