helloWorldIsAlliKnow
helloWorldIsAlliKnow

Reputation: 77

Uncaught ReferenceError: swapImage is not defines

I'm pretty new to this but here is the deal.

At first I was having trouble because only one of my javascript elements would display. I've gotten some help from matt ellen and it came to my attention that I had window.onload in my code twice. Ive since removed them from the functions and added a line where I include both functions.

<head>

    <link rel="shortcut icon" href="bavafavicon"/>
    <title>Berlin Airlift Veterans Association: News</title>
    <link rel="stylesheet" type="text/css" href="main.css">

</head>

<body id="news">
    <div id="container">

        <div id="left"></div>
        <div id="leftblue"></div>
        <div id="right"></div>
        <div id="topyellow"></div>
        <div id="topred"></div>

        <div id="slider">           
            <script type="javascript"> 
                var i = 0; var path = new Array(); 
                    path[0] = "1.jpg"; 
                    path[1] = "2.jpg"; 
                    path[2] = "3.jpg"; 
                    path[3] = "4.jpg";
                    path[4] = "5.jpg";
                    path[5] = "6.jpg";
                function swapImage() 
                    { 
                        document.slide.src = path[i]; 
                        if(i < path.length - 1) i++; 
                        else i = 0; 
                        setTimeout("swapImage()",5500); 
                    } 
            </script> 
            <img name="slide"/>
        </div>

            <ul id="head_nav">
                <li><a href="index.htm" class="currentButton">NEWS</a></li>
                <li><a href="aboutbava.htm" class="button">ABOUT BAVA</a></li>
                <li><a href="history.htm" class="button">HISTORY</a></li>
                <li><a href="biographies.htm" class="button">BIOGRAPHIES</a></li>
                <li><a href="calendar.htm" class="button">CALENDAR</a></li>
                <li><a href="contact.htm" class="button">CONTACT</a></li>
                <li><a href="links.htm" class="button">LINKS</a></li>
                <li><a href="donate.htm" class="button">DONATE</a></li>
            </ul>

            <div id="headlogo">
                <img src="BAVA.png" alt="BAVA logo" width="150" height="150"/>
            </div>
            <div id="subscribe">Sign up for BAVA updates!<br>

                <img src="emailBomb.png" alt="emailBomb" id="emailBomb" width="150" height="300"/>
                <form action="demo_form.asp">
                    E-mail: <input type="email" name="userid">
                    <input type="submit" value="Submit"><br></form> 

<script type="javascript">

function GetClock(){
tzOffset = +2;

d = new Date();
dx = d.toGMTString();
dx = dx.substr(0,dx.length -3);
d.setTime(Date.parse(dx))
d.setHours(d.getHours() + tzOffset);
nday   = d.getDay();
nmonth = d.getMonth();
ndate  = d.getDate();
nyear = d.getYear();
nhour  = d.getHours();
nmin   = d.getMinutes();
if(nyear<1000) nyear=nyear+1900;

if(nmin <= 9){nmin="0"+nmin}


document.getElementById('berlinClock').innerHTML=""+(nmonth+1)+"/"+ndate+"/"+nyear+"       "+nhour+":"+nmin+"";
setTimeout("GetClock()", 1000);
}
</script> <script type="text/javascript" language="javascript">
                    window.onload = function() { swapImage(); GetClock(); };
                </script>               
<div id="berlinClock"></div>



            </div>


        </div>
    <footer>
        <div id="footer">
            <p><i>15 N. College Ave, Newton, NC 28658   |   (828) 466-3410</i></p>
        </div>
    </footer>

</body>

Im no longer using an external js.

Upvotes: 1

Views: 390

Answers (1)

Matt Ellen
Matt Ellen

Reputation: 11592

You set the window.onload twice. It will be the second one, which is GetClock, which will be run, not the first.

You need to add a function call that calls both after you've declared both functions, and then remove the other assignments to onload.

window.onload = function() { swapImage(); GetClock(); };

Here's a fiddle to demonstrate what I mean.

As an aside; your language attribute is incorrect in your first script tag. It should be javascript not JavasScript/text.

Upvotes: 2

Related Questions