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:
  #16  
Old March 23rd, 2009, 04:40 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 changed it so it should be good for both IE and etc:
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 {
//your old code                                                   img.attachEvent('onClick', bombard);
//replaced with:
img.onclick= function(){bombard(i+tmpA[bn]+ii)}
			}

//end new code
__________________
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
  #17  
Old March 23rd, 2009, 08:06 PM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
its reasons like this that I love using jquery for handling javascript stuff.

Code:
<html>
<head>
<title>This is a test</title>
<style type="text/css">
#testTable { border-right: 1px solid black; border-bottom: 1px solid black; border-collapse: collapse; }
#testTable td { padding: 3px; border-top: 1px solid black; border-left: 1px solid black; }
#testTable td.selectedCell { background-color: #0099FF; }
#testTable td.selectedRow { background-color: #99CCFF; }
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('#testTable td').click(function(e){
        alert(e.target.id);
        $('#testTable td').removeClass('selectedCell').removeClass('sele  ctedRow');
        $(e.target).addClass('selectedCell').siblings().ad  dClass('selectedRow');
    });
});
</script>
</head>
<body>

<table id="testTable">
  <tr id='row1'>
    <td id='cell1_1'>Cell 1-1</td>
    <td id='cell1_2'>Cell 1-2</td>
    <td id='cell1_3'>Cell 1-3</td>
    <td id='cell1_4'>Cell 1-4</td>
    <td id='cell1_5'>Cell 1-5</td>
  </tr>
  <tr id='row2'>
    <td id='cell2_1'>Cell 2-1</td>
    <td id='cell2_2'>Cell 2-2</td>
    <td id='cell2_3'>Cell 2-3</td>
    <td id='cell2_4'>Cell 2-4</td>
    <td id='cell2_5'>Cell 2-5</td>
  </tr>
  <tr id='row3'>
    <td id='cell3_1'>cell 3-1</td>
    <td id='cell3_2'>cell 3-2</td>
    <td id='cell3_3'>cell 3-3</td>
    <td id='cell3_4'>cell 3-4</td>
    <td id='cell3_5'>cell 3-5</td>
  </tr>
  <tr id='row4'>
    <td id='cell4_1'>cell 4-1</td>
    <td id='cell4_2'>cell 4-2</td>
    <td id='cell4_3'>cell 4-3</td>
    <td id='cell4_4'>cell 4-4</td>
    <td id='cell4_5'>cell 4-5</td>
  </tr>
  <tr id='row5'>
    <td id='cell5_1'>cell 5-1</td>
    <td id='cell5_2'>cell 5-2</td>
    <td id='cell5_3'>cell 5-3</td>
    <td id='cell5_4'>cell 5-4</td>
    <td id='cell5_5'>cell 5-5</td>
  </tr>
</table>

</body>
</html>

Seriously, it makes it much easier once you get the hang of it. I REALLY suggest it and also suggest you get a book about jquery and learn it.

Reply With Quote
  #18  
Old March 24th, 2009, 05:03 AM
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
Sorry, only had access to the script at work, so not been able to test it

Still not working, although I have just realised that it is redundant now, as the cells I need this applying to don't need the thiscell() in the first place, so when I write the table all I need to do is put the bombard() in the onclick and just check that the status of the script is in the correct place and do the rest of the function there.

This is what happens when you spend 7 hours straight staring at code, your brain frazzles and simple connections like that aren't made >.<
__________________
~~==~~ Whoever said nothing is impossible never tried pushing a revolving door ~~==~~

Reply With Quote
  #19  
Old October 9th, 2009, 09:39 PM
connumqui connumqui is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 1 connumqui User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 36 sec
Reputation Power: 0
Oh! Thank you so much for the post. It's really useful.
Good post. I appreciate it

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