...

View Full Version : window.alert not appearing



andynov123
11-13-2012, 04:27 PM
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>

DanInMa
11-13-2012, 04:29 PM
just use alert, not window.alert

WolfShade
11-13-2012, 04:36 PM
That's going to be an annoying event - the alert is inside the for loop.

DaveyErwin
11-13-2012, 04:59 PM
<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;

coothead
11-13-2012, 05:26 PM
Hi there andynov123,

I have commented out the errors...


<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

andynov123
11-13-2012, 05:54 PM
Thanks it works now!

coothead
11-13-2012, 06:02 PM
No problem, you're very welcome. ;)



coothead

felgall
11-13-2012, 08:59 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum