Enjoy an ad free experience by logging in. Not a member yet?
Register .
11-13-2012, 04:27 PM
PM User |
#1
Regular Coder
Join Date: Oct 2010
Posts: 246
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 ..
11-13-2012, 04:29 PM
PM User |
#2
Senior Coder
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,306
Thanks: 12
Thanked 204 Times in 204 Posts
just use alert, not window.alert
11-13-2012, 04:36 PM
PM User |
#3
Regular Coder
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 941
Thanks: 7
Thanked 95 Times in 95 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".
11-13-2012, 04:59 PM
PM User |
#4
Regular Coder
Join Date: Aug 2010
Posts: 806
Thanks: 12
Thanked 168 Times in 166 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;
11-13-2012, 05:26 PM
PM User |
#5
Senior Coder
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
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
11-13-2012, 05:54 PM
PM User |
#6
Regular Coder
Join Date: Oct 2010
Posts: 246
Thanks: 8
Thanked 1 Time in 1 Post
Thanks it works now!
11-13-2012, 06:02 PM
PM User |
#7
Senior Coder
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
No problem, you're very welcome.
coothead
11-13-2012, 08:59 PM
PM User |
#8
Master Coder
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
Quote:
Originally Posted by
WolfShade
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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 03:03 PM .
Advertisement
Log in to turn off these ads.