Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    need some help on a voting script

    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!


    Code:
    <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>

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,763
    Thanks
    23
    Thanked 548 Times in 547 Posts
    You work out the ties:
    Code:
    <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>
    Evolution - The non-random survival of random variants.

  • Users who have thanked sunfighter for this post:

    deff (03-27-2013)

  • #3
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much =D


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •