IT Community - Software Programming, Web Development and Technical Support

OnClick event for dynamic table?

This is a discussion on OnClick event for dynamic table? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all, Actually, I want to be able to do is assign an onclick event to a TD which will ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 09-28-2007, 12:41 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question OnClick event for dynamic table?

Hi all,

Actually, I want to be able to do is assign an onclick event to a TD which will call the function changeMonth. I've tried a few ways of doing it, but I keep receiving undefined errors for the function. Here's the td element I'm trying to add the event to:
Code:
var currentTD = document.createElement("td");
	currentTD.className = "calendarNav";
	currentTD.appendChild(document.createTextNode("<"));
	currentTD.setAttribute("onclick","this.changeMonth(-1)");
	currentTR.appendChild(currentTD);
and here's the function I'm trying to call:

Code:
Calendar.prototype.changeMonth = function(month){
	this.currentMonth += month;
	if (this.currentMonth > 11){
		this.currentMonth -= 12;
		this.currentYear++;
	}
	else if (this.currentMonth < 0){
		this.currentMonth = 12 + month;
		this.currentYear--;
	}
	document.write(currentMonth);
}
I've tried using various ways of attachEvent and setAttribute, but I can't seem to get anything to work. Any help would be greatly appreciated
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-06-2007, 06:01 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Wink Re: OnClick event for dynamic table?

Hi vinoth!

Have you tried this?

Code:
currentTD.onclick = this.changeMonth(-1);
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-06-2007, 07:07 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Smile Re: OnClick event for dynamic table?

Code:
currentTD.onclick = function(){this.changeMonth(-1);}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-06-2007, 07:12 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Question Re: OnClick event for dynamic table?

Yes, I tried that..The problem is that the instance of the Calendar class is created:

Code:
var cal = new Calendar();
cal.buildCalendar();
but when the entire thing is added to the document.body, it loses it's reference, and therefore doesn't understand the 'this' keyword anymore. Every error I'm getting in Firefox's web developer seems to be pointing to this as the problem.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-10-2007, 11:59 PM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Default Re: OnClick event for dynamic table?

Can you show me your coding where you are putting this into the page?
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-11-2007, 12:08 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Default Re: OnClick event for dynamic table?

Ya Sure,..

Code:
function Calendar(){
	this.monthNames = new Array("January","February",....);
	this.monthDays = new Array(31,28,31,30,31,30,31,....);
	this.daysOfWeek = "SMTWTFS";
	this.currentDate = new Date();
	this.currentMonth = this.currentDate.getMonth();
	this.currentYear = this.currentDate.getFullYear();
}

Calendar.prototype.changeMonth = function(month){
}

Calendar.prototype.buildCalendar = function(){
        ............
	var currentTD = document.createElement("td");
	currentTD.className = "calendarNav";
	currentTD.appendChild(document.createTextNode("<"));
	currentTR.appendChild(currentTD);
        ............
}

Calendar.prototype.leapCheck = function(year){
}

var cal = new Calendar();
cal.buildCalendar();
and calling in the html is,

Code:
<body>
<script language = 'JavaScript' type = 'text/javascript' src = '/class/class_Calendar.js'>
</script>
</body>
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-11-2007, 04:22 AM
krishnakumar krishnakumar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 206
krishnakumar is on a distinguished road
Smile Re: OnClick event for dynamic table?

I believe you need to make sure that every element you're putting in the document uses the .appendChild() function. Something like this,

Code:
vary body = document.body;
var table = document.createElement("table");
var tr = document.createElement("tr");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
tr.appendChild(td1);
tr.appendChild(td2);
table.appendChild(tr);
body.appendChild(body);
__________________
Krishnakumar.S
Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 10-11-2007, 11:45 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Default Re: OnClick event for dynamic table?

Oh thank you buddy!

I will check it out...
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between DELETE TABLE and TRUNCATE TABLE commands in SQL Server oxygen Database Support 6 11-23-2007 06:17 AM
event.clientX and event.clientY is working in IE but not work in firefox? senraj HTML, CSS and Javascript Coding Techniques 2 08-08-2007 05:27 AM
please explain about how to create dynamic table in pdf by using pdf function saravanan PHP Programming 0 07-30-2007 06:25 AM
Static IP & Dynamic IP vadivelanvaidyanathan Server Management 0 07-15-2007 06:53 PM
applying dynamic motion nssukumar Flash Actionscript Programming 0 02-28-2007 06:18 AM


All times are GMT -7. The time now is 11:44 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0