Help needed with javascript in html

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

14-Apr-12 18:32
Hello everyone. I'm new to html and I need help using javascript in a web page. The page is for my html class and it 's suppose to dynamically update the date and amount of days till the final exam. However, this output won't display. Here is the complete code for my web page;


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Homework 4</title>
</head>
<body>
<table border="0" align="center" width="800">
<tr>
<td><img src="homework4-2banner.jpg" width="800" height="150" alt="homework 4-2 banner" /></td>
</tr>
<tr>
<td><img src="bluedivider.jpg" width="800" alt="blue divider image" /></td>
</tr>
<tr>
<td>
<p style="margin-left">
<script type="text/javascript">
<!--Hide from old browsers
var today = new Date()
var dayofweek = today.toLocaleString()
dayLocate = dayofweek.indexOf(" ")
weekDay = dayofweek.substring(0, dayLocate)
newDay = dayofweek.substring(dayLocate)
dateLocate = newDay.indexOf(",")
monthDate = newDay.substring(0, dateLocate+1)
yearLocate = dayofweek.indexOf("2012")
year = dayofweek.substr(yearLocate, 4)

var finalexamDate = new Date("April 30, 2012")
Var daysToGo = finalexamDate.getTime()-today.getTime()
var daysToFinalExam = Math.ceil(daysToGo/(1000*60*60*24))

document.write("<p style='margin-left:10%; font-family:Arial, sans-serif; font-weight:bold; font-color:black; font-size:14'>Today is
"+weekDay+" "+monthDate+" "+year+".")
document.write("The online final exam will be posted in "+daysToFinalExam+".")
document.write("<br/>It will focus on the topics, which have been covered after the midterm exam.</p>")

//-->
</script>
</p>
</td>
</tr>
<tr>
<td><img src="bluedivider.jpg" width="800" alt="blue divider image" /></td>
</tr>

<tr>
<td><p> This course introduces students to the World Wide Web, focusing on the techniques of web page creation. No <br/> programming background is required, although students will learn some programming through script languages.
<br/>
<br/>

Key concepts and major topics of this course including:</p>

<ol>
<li> Color and text with cascading style sheets</li>
<li> Forms</li>
<li> Interactive Web Page: JavaScript</li>
<li> Tables</li>
<li> Web design tools</li>
<li> Web graphics</li>
<li> HTML</li>
</ol>

</td>
</tr>
<tr>
<td>
<script type="text/javascript">
<!--Hide from old browsers
document.write("<p style='margin-left; font-family:Arial, sans-serif; font-size:xx-small; color:blue'>")
document.write("This document was last modified "+document.lastModified+"</p>")
//-->
</script>
</td>
</tr>
</table>

</body>
</html>
15-Apr-12 03:36
Var daysToGo = finalexamDate.getTime()-today.getTime()
^
|_ shoulde be var

also i suggest you terminate each javascript line with ;

--
rshep2
16-Apr-12 06:14
Thank you for all your help rshep2. I'm new to programming and still have a lot to learn. I had a feeling I was forgetting so minor details like that v being lowercase or ending with semicolon. The book I'm using for HTML class didn't include the parenthesis after each line of JavaScript code. Again, I'm truly appreciative for the help you've given me.

[Edited by msuave7 on 16-Apr-12 12:20]

 
New posts
Old posts

Follow Elated