Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2012, 04:27 PM   PM User | #1
andynov123
Regular Coder

 
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
andynov123 is an unknown quantity at this point
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..
andynov123 is offline   Reply With Quote
Old 11-13-2012, 04:29 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,306
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
just use alert, not window.alert
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 11-13-2012, 04:36 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 11-13-2012, 04:59 PM   PM User | #4
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 806
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
<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;
DaveyErwin is offline   Reply With Quote
Old 11-13-2012, 05:26 PM   PM User | #5
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,545
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough
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
coothead is offline   Reply With Quote
Old 11-13-2012, 05:54 PM   PM User | #6
andynov123
Regular Coder

 
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
andynov123 is an unknown quantity at this point
Thanks it works now!
andynov123 is offline   Reply With Quote
Old 11-13-2012, 06:02 PM   PM User | #7
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,545
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough

No problem, you're very welcome.

coothead
coothead is offline   Reply With Quote
Old 11-13-2012, 08:59 PM   PM User | #8
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:03 PM.


Advertisement
Log in to turn off these ads.