Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    260
    Thanks
    8
    Thanked 1 Time in 1 Post

    window.alert not appearing

    Can someone tell me why my window.alert wont appear when I load the page?

    <?xml version="1.0" encoding="UTF-8" ?>

    <!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">


    <title>Congressional Races</title>
    <script type="text/javascript src="votes.js"></script>
    <script type ="text/javascript">
    function totalVotes(){
    var total = 0;
    var counter=0;
    var votes= = [94766, 168751, 116492, 103516, 86855];
    /*
    votes0[0] = 94766;
    votes1[1] = 168751;
    votes2[2] = 116492;
    votes3[3] = 103516;
    votes4[4] = 86855;
    */
    for(i=0; i<=votes[counter];i++){
    total = votes[i] + total;
    window.alert("The total is: " + total);
    }
    }

    </script>
    <script type="text/javascript">
    totalVotes();
    </script>
    <link href="results.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <div id="intro">
    <p><img src="logo.jpg" alt="Election Day Results" /></p>
    <a href="#">Election Home Page</a>
    <a href="#">President</a>
    <a href="#">Senate Races</a>
    <a href="#">Congressional Races</a>
    <a href="#">State Senate</a>
    <a href="#">State House</a>
    <a href="#">Local Races</a>
    <a href="#">Judicial</a>
    <a href="#">Referendums</a>
    </div>

    <div id="results">
    <h1>Congressional Races</h1>

    </div>

    </body>
    </html>
    Last edited by andynov123; 11-13-2012 at 04:29 PM.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    just use alert, not window.alert

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    That's going to be an annoying event - the alert is inside the for loop.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 Posts
    <title>Congressional Races</title>
    <script type="text/javascript src="votes.js"></script>
    <script type ="text/javascript">
    function totalVotes(){
    var total = 0;
    var counter=0;
    var votes= = [94766, 168751, 116492, 103516, 86855];
    /*
    votes0[0] = 94766;
    votes1[1] = 168751;

  • #5
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts
    Hi there andynov123,

    I have commented out the errors...
    Code:
    
    <script type ="text/javascript">
    function totalVotes(){
    var total = 0;
    //var counter=0;
    //var votes= = [94766, 168751, 116492, 103516, 86855];
      var votes= [94766, 168751, 116492, 103516, 86855];
    /*
    votes0[0] = 94766;
    votes1[1] = 168751;
    votes2[2] = 116492;
    votes3[3] = 103516;
    votes4[4] = 86855;
    */
    //for(i=0; i<=votes[counter];i++){
      for(i=0; i<votes.length;i++){
    total = votes[i] + total;
    window.alert("The total is: " + total);
    }
    }
    </script>
    
    <script type="text/javascript">
    totalVotes();
    </script>
    coothead

  • #6
    Regular Coder
    Join Date
    Oct 2010
    Posts
    260
    Thanks
    8
    Thanked 1 Time in 1 Post
    Thanks it works now!

  • #7
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,680
    Thanks
    0
    Thanked 230 Times in 225 Posts

    No problem, you're very welcome.


    coothead

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,458
    Thanks
    0
    Thanked 632 Times in 622 Posts
    Quote Originally Posted by WolfShade View Post
    That's going to be an annoying event - the alert is inside the for loop.
    No it isn't - most browsers now contain an extra checkbox in the alerts that they display that will either prevent the page displaying additional alerts or will turn JavaScript off for the page. Simply check that box and there will be no more annoying alerts generated by the page.

    Anyway the aledrt should have been removed prior to the page going live as alert is intended for debugging scripts and not for use in live web pages.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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