Jump to content

Event Handler for a Single Table Cell


proggR

Recommended Posts

So I wasn't really paying attention in my JS class the other day but I managed to copy the code on the board. I basically have a 12 month calendar on the left of the screen and I have an hour-by-hour break down of an individual day on the right. When you click a day it is supposed to update the header of the day table to change the date. We don't have to have any information in the hours of the day because I think he's going to get us to script that to pull from a server at a later time.

If someone could explain how to change data post-rendering it would be helpful. I know its something easy and I'm just farting really loud in my brain.

The code snippet he gave is:

<td id="schedule-date"></td>

**inside handler**

var scheduleCell=document.getElementByID("schedule-date");

scheduleCell.innerHTML(month+" "+day);

 

For some reason its not liking when my onclick passes more than just one variable so for right now it only passes the day to a function. I have an alert in the function display the day and that works. Its not, however, displaying the day in the contents of the table. Here are those sections of my code:

//the script that makes the calendar
for(ctr=lastDay;ctr<=7;ctr++){
    document.write("<td onclick=\"displayDat("+day+");\">"+day+"</td>");
    day++;
} //just a portion, this would only do a week, assuming lastDay was 1

// the function that gets called
function displayDat(day){
alert(day);
var scheduleCell=document.getElementByID("schedule-date");
scheduleCell.innerHTML(day);
}

//the function that makes the day table
  function displayAppt(){
 var hour;
 document.write("<table border='1'><tr><td id=\"schedule-date\" colspan='2' rowspan='1'></td></tr>");
   for (hour=8;hour<=18;hour++){
   document.write("<tr><td width='20'>"+hour+":00</td><td></td></tr>");  
   document.write("<tr><td width='20'>"+hour+":30</td><td></td></tr>");
}
document.write("</table>");
}

 

I know its not your homework and clearly I'm doing something wrong, but any help would be great.

 

Link to comment
https://forums.phpfreaks.com/topic/142006-event-handler-for-a-single-table-cell/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.