SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    script was not interpreted at all (was "help a beginner")

    hello. im a javascript beginner. as of now, my reference is Sam's Teachyourself JavaScript 1.3 in 24Hours.

    i tried to program a simple .html page.
    i didnt get the result i expected--the script was not interpreted at all.
    i am using iexplorer version 6 though.

    here is the code i managed to do:
    ================================

    <HTML><HEAD><TITLE>Exercise 1</TITLE></HEAD>
    <BODY>
    <H1>
    <P>Compilation of Part I Exercises</H1>
    <HR>

    <SCRIPT language=JavaScript>
    refresh=date.lastModified();
    now=new Date();
    deadline=new Date("July 08 2006 00:00:00");
    document.write("<h2><p>I worked on this date: " + refresh + "<p></h2>");
    time_remaining=(((deadline - now)/1000)/60)/60; //hours
    document.write("<p>Time remaining to complete this course: " + time_remaining + "<p>");
    </SCRIPT>

    <HR>
    </BODY></HTML>
    ================================

    printscreen attachment: windows.png
    i dont know what seem to be wrong with my lines.
    hope you can help me so i can progress to the next activities.
    Attached Images Attached Images

  2. #2
    SitePoint Zealot coothead's Avatar
    Join Date
    Jan 2005
    Location
    Chertsey, London, England
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there xxhe,

    and a warm welcome to these forums.

    this...
    Code:
    refresh=date.lastModified();
    ...should be...
    Code:
    refresh=document.lastModified;
    Note that language="JavaScript" is a deprecated attribute, use type="text/javascript" instead.
    It is also advisable to use a DOCTYPE as a matter of habit.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Exercise 1</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <h1>Compilation of Part I Exercises</h1>
    
    <hr>
    
    <script type="text/javascript">
    <!--
    
      refresh=document.lastModified;
      now=new Date();
      deadline=new Date("July 08 2006 00:00:00");
      time_remaining=(((deadline - now)/1000)/60)/60; //hours
    
      document.write("<h2>I worked on this date: " + refresh + "<\/h2>");
      document.write("<p>Time remaining to complete this course: " + time_remaining + "<\/p>");
    
    //-->
    </script>
    
    <hr>
    
    </body>
    </html>
    coothead

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,815
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The <!-- --> around the javascript can result in it being treated as comments by the latest browsers and document.write isn't supported by XHTML (the successor to HTML).

    From the look of the code that book is several years old and way out of date. The latest version of Javascript is 1.6 and there have been lots of changes over that time especially as to how to interact between Javascript and the content of the web page - especially the way you can manipulate the way the page looks by updating the stylesheet.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •