This is a voting system:

all i want is when you click the submit button the data that is selected will be validated and link to another page. but if you click the cancel button in the confirm message dialog in it will continue right away.


here is the full code:

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/wowwindow.css">

<script type="text/javascript">
$(document).ready(function(){
$("#form1").validateMyForm({ textareaLimit:225 });
$(document).ready(function() {
$('.popups a').wowwindow({
draggable: false
});
});
});
</script>
<script language = "javascript">

function checkRadio (frmName, rbGroupName) {
var radios = document[frmName].elements[rbGroupName];
for (var i=0; i <radios.length; i++) {
if (radios[i].checked) {
return true;
}
}
return false;
}

function valFrm() {

if(!checkRadio("form1","Governor"))
alert("Please select a Governor");
else if (!checkRadio("form1","Vice_Governor"))
alert("Please select a Vice Governor");
else if (!checkRadio("form1","Secretary"))
alert("Please select a Secretary");
else if (!checkRadio("form1","Treasurer"))
alert("Please select a Treasurer");
else if (!checkRadio("form1","assisTreasurer"))
alert("Please select a Assistant Treasurer");

else
confirmation()

}

function displayGov()
{
for (var i = 0; i < document.form1.Governor.length; i++)
{
if (document.form1.Governor[i].checked)
{
var display = document.form1.Governor[i].value;
//alert("Governor \n" + display);
return display;
}
}
}

function displayVice()
{
for (var i = 0; i < document.form1.Vice_Governor.length; i++)
{
if (document.form1.Vice_Governor[i].checked)
{
var display = document.form1.Vice_Governor[i].value;
//alert("Vice Governor \n" + display);
return display;
}
}
}

function displaySec()
{
for (var i = 0; i < document.form1.Secretary.length; i++)
{
if (document.form1.Secretary[i].checked)
{
var display = document.form1.Secretary[i].value;
//alert("Secretary \n" + display);
return display;
}
}
}

function displayTre()
{
for (var i = 0; i < document.form1.Treasurer.length; i++)
{
if (document.form1.Treasurer[i].checked)
{
var display = document.form1.Treasurer[i].value;
//alert("Secretary \n" + display);
return display;
}
}
}
function summary(){

//displayGov()
//displayVice()
//displaySec()
alert("YOUR VOTE SUMMARY: \n \n" + "Governor: " + displayGov() + "\n \n" + "Vice Governor: " + displayVice() + "\n \n" + "Secretary: " + displaySec() + "\n \n" + "Treasurer: " +displayTre());

}

function confirmation() {
summary();
//displayGov()
//displayVice()
//displaySec()
var answer = confirm("Cast vote?");
if (answer){
alert("Thank you for casting vote");
go();
}

}
///function go() {
//alert("S");
//window.location="includes/saving.php";
//}

</script>
</head>
<div>
<?php

if(!empty($_REQUEST['sb'])){
include("includes/saving.php");
}
else{
$conn = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("election") or die(mysql_error());

$sql4= "SELECT image FROM candidates WHERE position='governor'";
$result4= mysql_query($sql4) or die(mysql_error());
?>
<!--<span id="es"></span>-->
<div class="content">
<center><fieldset id = "container">
<br>
<div id="header">

<div id="headerText">
<img src="images/razor.png" height = "150">
</div>

</div>
<br>
<center><table width = 1050 border = "0" bgcolor= #256d87>

<tr>
<td align = "center" class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time">GOVERNOR</td></h3>
</tr>
<!--------------------Governor---------------------->
<tr>
<?php

while ($row = mysql_fetch_assoc($result4)){ ?>

<?php echo '<td align=center>' . "<img src=' ".$row['image']." ' height=80 width = 120>"; ?>
<?php }?>
</tr>
<tr>
<?php
$sql5= "SELECT name FROM candidates WHERE position='governor'";
$result5= mysql_query($sql5) or die(mysql_error());
while($row = mysql_fetch_assoc($result5)) { ?>

<FORM METHOD = "POST" NAME="form1" ACTION = "#">

<td class = "gov" align="center"><input type="radio" name="Governor" value="<?php echo $row['name'];?>"><?php echo $row['name'];?></td>
<?php
}
?>
</tr>
<p>
<!------------------ViceGovernor-------------------->
<tr>
<td align = "center" class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time" >VICE-GOVERNOR</td></h3>
</tr>

<tr>
<?php
$sql6= "SELECT image FROM candidates WHERE position='vicegovernor'";
$result6= mysql_query($sql6) or die(mysql_error());
while($row = mysql_fetch_assoc($result6))
{
?>
<!--<td class = "gov" align="center"><img src = "../includes/<?php $row['image'];?>" width = "120" height = "80"></td>-->
<?php echo '<td align=center>' . "<img src=' ".$row['image']." ' height=80 width = 120>"; ?>
<?php } ?>
</tr>

<tr>

<?php
$sql7= "SELECT name FROM candidates WHERE position='vicegovernor'";
$result7= mysql_query($sql7) or die(mysql_error());
while($row = mysql_fetch_assoc($result7))
{
?>
<td class = "gov" align="center"><input type="radio" name="Vice_Governor" value="<?php echo $row['name'];?>"><?php echo $row['name'];?></td>
<?php
}
?>
</tr>
<p>

<!-------------------Secretary--------------------->

<tr>
<td align = "center" class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time" >SECRETARY</td></h3>
</tr>

<tr>
<?php
$sql8= "SELECT image FROM candidates WHERE position='secretary'";
$result8= mysql_query($sql8) or die(mysql_error());
while($row = mysql_fetch_assoc($result8))
{
?>
<!--<td class = "gov" align="center"><img src = "<?php $row['image'];?>" width = "120" height = "80"></td> -->
<?php echo '<td align=center>' . "<img src=' ".$row['image']." ' height=80 width = 120>"; ?>
<?php } ?>
</tr>
<tr>
</tr>
<tr>

<?php
$sql9= "SELECT * FROM candidates WHERE position='secretary'";
$result9= mysql_query($sql9) or die(mysql_error());
while($row = mysql_fetch_assoc($result9))
{
?>
<td class = "gov" align="center"><input type="radio" name="Secretary" value="<?php echo $row['name'];?>"><?php echo $row['name'];?></td>
<?php
}
?>
</tr>
<p>
<!-------new candidate--------------------------------------------------->

<tr>
<td align = "center" class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time" >TREASURER</td></h3>
</tr>

<tr>
<?php
$sql10= "SELECT image FROM candidates WHERE position='Treasurer'";
$result10= mysql_query($sql10) or die(mysql_error());
while($row = mysql_fetch_assoc($result10))
{
?>
<!--<td class = "gov" align="center"><img src = "<?php $row['image'];?>" width = "120" height = "80"></td> -->
<?php echo '<td align=center>' . "<img src=' ".$row['image']." ' height=80 width = 120>"; ?>
<?php } ?>
</tr>
<tr>

<?php
$sql11= "SELECT * FROM candidates WHERE position='Treasurer'";
$result11= mysql_query($sql11) or die(mysql_error());
while($row = mysql_fetch_assoc($result11))
{
?>
<td class = "gov" align="center"><input type="radio" name="Treasurer" value="<?php echo $row['name'];?>"><?php echo $row['name'];?></td>
<?php
}
?>
</tr>
<p>

<!---assistant treasurer--->

<tr>
<td align = "center" class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time" >ASSISTANT TREASURER</td></h3>
</tr>

<tr>
<td class = "pos" colspan = 3><hr width="90%" color="#D0D0D0 " size="1" /><h3 class = "time" >
</tr>
<p>

<tr>
<center><td>&nbsp </td>
<td align="center"><input type="submit" value="SUBMIT" name="sb" onclick = "javascript:valFrm();"><input type="reset" value="RESET"></td></center>
<input type="hidden" value="$username" name="code"></tr>

<?php
}
?>
</form>
</table>
</fieldset>
</center>
</div>
</html>