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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.