简体   繁体   中英

javascript won't execute functions

I have the following code written that should do the following: - Create a dynamic message with a countdown - Change the scrollbar color (use #20409a for the scroll bar face color and #ffde20 for the scroll bar track color) - Use the selected index in the select tag to link to new webpages - Add URL, copyright notice, date the Webpage was last modified

However when I launch the website I get a standard webpage, what am I doing wrong or have I missed. Thanks for your help.

<!DOCTYPE HTML>

<html>
    <head>
        <meta charset="utf-8">
        <title>Unit 4 - A2</title>
        <script type="text/javascript">
            function countDown() {
                var today = new Date()                              // Obtain current system date
                var dayofweek = today.toLocaleString()              // Convert date to a string that can be manipulated  Day, Month Date, Year HH:MM:SS AM/PM

                dayLocate = dayofweek.indexOf(" ")                  // Use indexOF() method to find the space between the month and day of the week to extract the month
                weekDay = dayofweek.substring(0, dayLocate)         // Use substring method to extract the day of the week from the string
                newDay = dayofweek.substring(dayLocate)             // Use substring to extract the remainder of the date from the strong
                dateLocate = newDay.indexOf(",")                    // 
                monthDate = newDay.substring(0, dateLocate + 1)
                yearLocate = dayofweek.indexOf("2015")
                year = dayofweek.substr(yearLocate, 4)

                var DateOfLaunch = new Date("July 31, 2015")
                var daysToGo = DateOfLaunch.getTime()-today.getTime()
                var daysToLaunch = Math.ceil(daysToGo/(1000*60*60*24))
            }

            function scrollColor() {
                styleObject = document.getElementsByTagName('html')[0].style
                styleObject.scrollbarFaceColor = "#20409a"
                styleObject.scrollbarTrackColor = "#ffde20"
            }

            function loadInfo(myForm) {
                var menuSelect = myForm.Menu.selectedIndex
                var menuUrl = myForm.Menu.options[menuSelect].value + ".html"
                window.location = menuUrl
            }

            funtion copyRight () {
                var lastModDate = document.lastModified
                var lastModDate = lastModDate.substring(0,10)

                displayCopyRight.innerHTML = "<h6>The URL of this document is" + document.URL + "<br />Copyright Smart Homes System<br />This document was last modified " + lastModDate + ".</h6>"
            }
        </script>
        <style type="text/css">
            .center {
                text-align: center;
            }

            table {
                margin-left: 15%;
                margin-right: 15%;
            }

            .cell-width {
                width: 50%;
            }

            .left-align {
                width: 50%;
                left: 0px;
            }

            .right-align {
                width: 50%;
                right: 0px;
                text-align: right;
            }

            .smallprint {
                "Times New Roman", Times, serif;
                font-weight: bold;
            }

            .textheadings {
                font-weight: bold;
            }
        </style>
    </head>

    <body>
        <div class="center">
            <p><img src="banner-product.jpg" alt="Smart Homes, Inc banner"></p>
            <p style="font-weight: bold;">About the Smart Homes System</p>
                <img src="hrimg.gif" width="750px" height="5px" alt="hr line">
        </div>
        <div id=displayDate>
        </div>
        <table>
            <tr>
                <td colspan="2">
                    <p style="font-weight: bold;">The Smart Homes System</p>
                    <p>Smart Homes is an innovative home thermostat learns the usage patterns of its home's occupants over time and uses the data it collects to program itself to save money and energy. Additionally, the product allows owners to remotely control and program the thermostat via mobile computing devices such as Apple's iPhone and Google's Android.</p>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <form id="announceMenu" action=" ">
                        <p style="font-weight: bolder;">Select an item from the list to see other current announcements:
                            <select name="Menu" onchange="loadInfo(this.form)">
                                <option>Select an item</option>
                                <option value="products">Products</option>
                                <option value="tickets">Prices</option>
                                <option value="listings">Features</option>
                                <option value="locations">Retail Locations</option>
                            </select>
                        </p>
                    </form>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <p style="font-weight: bold;">Installation Guide</p>
                    <p>Smart Homes technology is easy to install! Detailed instruction.</p>
                </td>
            </tr>
            <tr>
                <td class="right-align">
                    <img src="image.jpg" alt="title" width="321px" height="160px">
                </td>
                <td class="left-align">
                    <img src="image2.jpg" alt="title" width="246px" height="161px">
                </td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="2">&nbsp;</td>
            </tr>
        </table>
        <div id="displayCopyRight">
        </div>
    </body>
</html>

You have only defined the functions, you never call them. You need to call the functions to execute them.

I also would suggest moving your entire script to down just before the /body tag.

So, like this:

        <div id="displayCopyRight">
        </div>

        <script>
            // your other JS code goes here...

            countDown();
            scrollColor();
            loadInfo();
            copyRight();
        </script>
    </body>
</html>

You have made a spelling mistake of "function". By mistake you have written "funtion". Correct it.

function copyRight () {
            var lastModDate = document.lastModified
            var lastModDate = lastModDate.substring(0,10)

            displayCopyRight.innerHTML = "<h6>The URL of this document is" + document.URL + "<br />Copyright Smart Homes System<br />This document was last modified " + lastModDate + ".</h6>"
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM