<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Vote for the best logo!</title>
<link rel = "stylesheet" type = "text/css" href = "style.css"/>
<script type = "text/javascript" language = "JavaScript">
function check()
{
var selected = 0;
if (document.getElementsByName("voting1").checked)
selected ++;
if (document.getElementsByName("voting2").checked)
selected ++;
if (document.getElementsByName("voting3").checked)
selected ++;
if (document.getElementsByName("voting4").checked)
selected ++;
if (document.getElementsByName("voting5").checked)
selected ++;
if (selected == 0)
{
alert ("You must vote for at least one logo to continue.");
return false;
}
else if (selected <= 2)
{
return true;
}
else
{
alert ("You cannot vote for more than two logos.")
return false;
}
}
</script>
</head>
<body>
<div id = "allcontent">
<form action = "result.php" method = "POST" onsubmit= "return check()">
<center>
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting1" value = "1" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting2" value = "2" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting3" value = "3" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting4" value = "4" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting5" value = "5" /> <br /><br />
<input type = "submit" value = "Submit!"/> <br /><br />
</center>
</form>
</div>
</body>
</html>
It doesn't work properly
. No matter which box I check, the selected variable is always zero. It seems that the if-statement isn't executed at all. Any idea how to fix it?
P.S. if you see "c..." on the if-statement, it supposed to be "checked".
I did make the PHP working well, but not with the JavaScript. The validation of the form seems not working.
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Vote for the best logo!</title>
<link rel = "stylesheet" type = "text/css" href = "style.css"/>
<script type = "text/javascript" language = "JavaScript">
function check()
{
var selected = 0;
if (document.getElementsByName("voting1").checked)
selected ++;
if (document.getElementsByName("voting2").checked)
selected ++;
if (document.getElementsByName("voting3").checked)
selected ++;
if (document.getElementsByName("voting4").checked)
selected ++;
if (document.getElementsByName("voting5").checked)
selected ++;
if (selected == 0)
{
alert ("You must vote for at least one logo to continue.");
return false;
}
else if (selected <= 2)
{
return true;
}
else
{
alert ("You cannot vote for more than two logos.")
return false;
}
}
</script>
</head>
<body>
<div id = "allcontent">
<form action = "result.php" method = "POST" onsubmit= "return check()">
<center>
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting1" value = "1" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting2" value = "2" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting3" value = "3" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting4" value = "4" /> <br /><br />
<img src = "xxx" alt = "xxx" /> <br /> Vote for this: <input type = "checkbox" name = "voting5" value = "5" /> <br /><br />
<input type = "submit" value = "Submit!"/> <br /><br />
</center>
</form>
</div>
</body>
</html>
It doesn't work properly

P.S. if you see "c..." on the if-statement, it supposed to be "checked".
I did make the PHP working well, but not with the JavaScript. The validation of the form seems not working.