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 ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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); 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);
}
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| Sponsored Links |
| |||
| 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 |
| |||
| Yes, I tried that..The problem is that the instance of the Calendar class is created: Code: var cal = new Calendar(); cal.buildCalendar();
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| 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 |
| |||
| 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(); 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! |
| |||
| 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 |
| |||
| 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! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |