PDA

View Full Version : need some help on a voting script



deff
Mar 27th, 2013, 09:40 AM
Hi,
i've been working on this code for a bit now and im not to sure why my logic script for showing me the winner is isn't working. as you can see its just a simple table with three buttons that tally votes shows the tally on the top. what I need to do is have 2 buttons in the 4th row, one that displays the current poll leader and one that hides it again. thanks a ton!



<html>
<head>

</head>
<body>
<form name = "Bean">
<script language = "JavaScript"
type="TEXT/JAVASCRIPT">
function addone(field) {
field.value = Number(field.value) + 1;
}

var winner = 0;
var argo = 0;
var les_mis = 0;
var lincoln = 0;
var whowon = 0;

document.write;

</script>

<table border="1">
<tr>
<td> <input type="text" name="lincoln" value="0" size="5">
</td>
<td><input type="text" name="les_mis" value="0" size="5">
</td>
<td><input type="text" name="argo" value="0" size="5">
</td>
</tr>
<tr>
<td>Lincoln
</td>
<td>Les Miserables
</td>
<td>Argo
</td>
</tr
<tr>
<td><input type="button" value="vote" onclick = "addone(lincoln);">

</td>
<td><input type="button" value="vote" onclick="addone(les_mis);">
</td>
<td><input type="button" value="vote" onclick="addone(argo);">
</td>
</tr>
<tr>
<td><input type=button value="current winner" onClick =
'winner = "lincoln";
da_winner = lincoln;
if (argo > da_winner)
{ winner = "Argo"; da_winner = argo;}
if (les_mis > da_winner)
{winner = "Les Mis"; da_winner = les_mis;}
document.Bean.winner_fb.value'>
</td>
<td><input type=text name=winner_fb value=" " size=5/>
</td>
<td>
</td>
</tr>
<tr>
<td><input type=button value="Reset"
onClick='
document.Bean.lincoln.value="0";
document.Bean.les_mis.value="0";
document.Bean.argo.value="0";'>
</td>
<td>
</td>
<td>
</td>
</tr>






</body>
</html>

sunfighter
Mar 27th, 2013, 02:32 PM
You work out the ties:

<html>
<head>
<script type="text/javascript">
var winner = 0;
var argo = 0;
var les_mis = 0;
var lincoln = 0;
var whowon = 0;
function addone(field) {
field.value = Number(field.value) + 1;
}
function findwinner(){
var x = document.Bean;
if(x.lincoln.value > x.les_mis.value)
var winner = "lincoln";
else
var winner = "les_mis";
if ((x.argo.value > x.les_mis.value) && (x.argo.value > x.lincoln.value)) var winner = "argo";
document.Bean.winner_fb.value = winner;
}
</script>
</head>

<body>
<form name = "Bean">
<table border="1">
<tr>
<td> <input type="text" name="lincoln" value="0" size="5"></td>
<td><input type="text" name="les_mis" value="0" size="5"></td>
<td><input type="text" name="argo" value="0" size="5"></td>
</tr>
<tr>
<td>Lincoln</td>
<td>Les Miserables</td>
<td>Argo</td>
</tr
<tr>
<td><input type="button" value="vote" onclick = "addone(lincoln);"> </td>
<td><input type="button" value="vote" onclick = "addone(les_mis);"> </td>
<td><input type="button" value="vote" onclick = "addone(argo);"> </td>
</tr>
<tr>
<td><input type=button value="current winner" onclick = "findwinner();"> </td>
<td><input type=text name=winner_fb value=" " size=5/> </td>
<td><input type=button value="hide the winner" onclick = "document.Bean.winner_fb.value = '';"></td>
</tr>
<tr>
<td><input type=button value="Reset"
onClick='
document.Bean.lincoln.value="0";
document.Bean.les_mis.value="0";
document.Bean.argo.value="0";'>
</td>
<td></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>

deff
Mar 27th, 2013, 05:04 PM
Thank you so much =D