Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Browsers only run some javascript - doesn't recognize most script  (Read 3424 times)

0 Members and 1 Guest are viewing this topic.

BarryP

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 7
    HI, I have a perplexing problem.  I am running IE 11, Firefox 26.5, and Safari. Neither browser recognizes my javascript other then the Alert command. Here's the code that works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

    <title>Untitled Document</title>
    </head>
    <body>
    <SCRIPT language="JavaScript">
    <!--
                 alert("alert-aliens attacking");
                 document.write("alert-aliens attacking");
                 document.write("hello")
    //-->
    </script>
    </body>
    </html>
     The Alert box comes up properly.

    When I run the following code;

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

    <head>
    <title>Displaying Times and Dates</title>
     <script type="text/javascript" >
    <!-- hide me
    var now1 = ""
    var Localtime1 = ""
    var Utctime1 = ""
    // end hide -->
    </script>
    </head>

    <body>

    <h1>Current Date and Time</h1>

     <script type="text/javascript" >

       alert("alert-aliens attacking");
    document.write("alert-aliens attacking");

       Now1 = New Date()
       localtime1 = now1.Tostring();
       utctime1 = now1.toGMTString();
       document.write("<strong>Local Time:<strong> '
        + Localtime1 + '
    ");
       document.write("<strong>UTC Time:</strong> " + utctime1);
    </script>

    </body>

    </html>

    Only the H1 displays.  Nothing else works. Am I missing something?

    Any assistance would be greatly appreciated.

    Barry