I've built a form for peolpe to submit a vote and I thought the best way to restrict people voting twice would be to create a cookie called "voted" and set the value to 1 when they vote.
When the page loads I want it to check for the cookie to see if that person has voted or not.
The script is creating a cookie called "vote" and setting it to 1.
I've attempted to write an if statement that checks this, but I can't get it to work.. What have I done wrong?
Thanks a lot!
Tom
Expand|Select|Wrap|Line Numbers
- <script language="javascript" src="cookies.js">
- function checkForVote(){
- if (getCookie("voted") == "1"){
- voteform.submitvote.disabled = true;
- }
- }
- checkForVote();
- </script>
- <form name="voteform" action="http://www.liv.ac.uk/cgi-bin/mailcomments.cgi" method="post">
- <input name="mailto" type="hidden" value="tcowling@liv.ac.uk">
- <input name="subject" type="hidden" value="Someone's Voted">
- <input name="required" type="hidden" value="email">
- <input name="email" type="hidden" value="someone@acomputer.com">
- <div align="center">
- <select name="select">
- <option>Candidate 1</option>
- <option>Candidate 2</option>
- </select>
- <br />
- <br />
- <input type="button" value="Submit Vote" onclick='setCookie("voted", "1")' name="submitvote" />
- </div>
- </form>