Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Please help - simple javascript program
Old 08-22-2004, 01:23 PM Please help - simple javascript program
Junior Talker

Posts: 2
Trades: 0
I've been working on JavaScript over the summer, trying to learn it. I've been making some simple programs to further my understanding. I made this calendar program, and I'm trying to make a different part light up based on the day that it is. I'd appreciate if someone could tell me why my code isn't working, I can't figure it out.

Here's the code:

HTML Code:
<html>
   <head>
      <title>
         Calendar Script
      </title>
 
<script language="javascript">


// light up whichever cell today's date is
// why dosen't this work???
function lightUp(celldate)
{
	var date = new Date()
	var day = date.getDate()


	if (celldate == day) {
		alert("if")
		document.getElementById(celldate).innerHtml =
		'<td ' +
		'width=14.2% ' +
		'bgcolor="yellow" ' +
		'> '
	}
	else {
		document.getElementById(celldate).innerHtml =
		'<td ' +
		'width=14.2% ' +
		'> '
		alert("else")
	}


}


</script>
 </head>

   <body


<font color=#FFFF10>
      <table cellspacing="0" cellpadding="4" border="1" width="80%" bgcolor="blue">

   <tr height=40>
      <td width=14.2%>
         <b>Monday</b>
      </td>
      <td width=14.2%>
         <b>Tuesday</b>
      </td>
      <td width=14.2%>
         <b>Wednesday</b>
      </td>
      <td width=14.2%>
         <b>Thursday</b>
      </td>
      <td width=14.2%>
         <b>Friday</b>
      </td>
      <td width=14.2%>
         <b>Saturday</b>
      </td>
      <td width=14.2%>
         <b>Sunday</b>
      </td>
   </tr>
   <tr valign=top>
      <td width=14.2%>
      &nbsp;
      </td>
      <td width=14.2%>
      &nbsp;
      </td>
      <div id=1>
       1
      </td>
      <div id=2>
         2
      </td>
      <div id=3>
         3
      </td>
      <div id=4>
         4
      </td>
      <div id=5>
         5
      </td>
   </tr>
   <tr valign=top>
      <div id=6>
         6
      </td>
      <div id=7>
         7
      </td>
      <div id=8>
         8
      </td>
      <div id=9>
         9
      </td>
      <div id=10>
         10
      </td>
      <div id=11>
         11
      </td>
      <div id=12>
         12
      </td>
   </tr>
   <tr valign=top>
      <div id=13>
         13
      </td>
      <div id=14>
         14
      </td>
      <div id=15>
         15
      </td>
      <div id=16>
         16
      </td>
      <div id=17>
         17
      </td>
      <div id=18>
         18
      </td>
      <div id=19>
         19
      </td>
   </tr>
   <tr valign=top>
      <div id=20>
         20
      </td>
      <div id=21>
         21
      </td>
      <div id=22>
         22
      </td>
      <div id=23>
         23
      </td>
      <div id=24>
         24
      </td>
      <div id=25>
         25
      </td>
      <div id=26>
         26
      </td>
   </tr>
   <tr valign=top>
      <div id=27>
         27
      </td>
      <div id=28>
         28
      </td>
      <div id=29>
         29
      </td>
      <div id=30>
         30
      </td>
      <div id=31>
         31
      </td>
      <td width=14.2%>
         &nbsp;
      </td>
      <td width=14.2%>
         &nbsp;
      </td>
   </tr>
</table>

</font>

   </body>

</html>

Last edited by Creaton; 08-22-2004 at 05:24 PM..
Creaton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-22-2004, 04:25 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
umm... Wheres your lightUp function called from? You have to call a function for it to work....
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Old 08-22-2004, 04:29 PM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
Creaton, it would help if you used code tags to format your code. It's hard to read without any indentation.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 08-22-2004, 05:22 PM
Junior Talker

Posts: 2
Trades: 0
srry forgot to inclue the call. To test I was calling it in the body with <body onload=lightUp(22)> - just to use today's date, but that wouldn't do anything.

Later I was going to put a for loop in, so that it would call 31 times, one for each div tag.

I'm just looking for how to actually light up the box, then I'll working on calling it (unless someone could help me with that?).

Last edited by Creaton; 08-22-2004 at 05:25 PM..
Creaton is offline
Reply With Quote
View Public Profile
 
Old 08-22-2004, 05:49 PM
webwoRRks's Avatar
Ultra Talker

Posts: 426
Location: I hope so
Trades: 0
You open with div, and close with td....
OK, start again. Do it all either TD's or DIV's, and assign each an id, and a style or class, with a default background colour. Then, when you want to highlight one, just do [itemID].style.backgroundColor="#CCFFEE"; Or some such thing. Far cleaner
__________________
Theres 10 types of people; those who understand binary, and those who don't.
webmaster and webdeveloper resources,
Please login or register to view this content. Registration is FREE
webwoRRks is offline
Reply With Quote
View Public Profile Visit webwoRRks's homepage!
 
Reply     « Reply to Please help - simple javascript program
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74195 seconds with 12 queries