Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<script src=""></script>
<script type="text/javascript">
//this code assumes jQuery is implemented, though it would not be difficult to do this with straight javascript. .ready() assures the code runs after the submit button is added
$(document).ready(function () {
var studyName="dm102513";//replace this value with a unique, acceptable cookie name... no spaces and stick with alphanumerics and underscores
var exdate=new Date();
exdate.setDate(exdate.getDate() + 365);
document.cookie=studyName+"=1; expires="+exdate.toUTCString()+";; path=/";//When the user clicks the Submit button, it creates a cookie that you can read later as having already completed this survey
var i,x,y,ARRcookies=document.cookie.split(";");//variables necessary to read the cookies. Last variables separates all available cookie names into an array we will loop through to find our cookie
for (i=0;i<ARRcookies.length;i++){
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));//x=cookie name
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);//y=cookie value
x=x.replace(/^\s+|\s+$/g,"");//Remove white space
if (x==studyName && y==1){
//If your cookie exists AND the value is 1, they have taken your survey before.
//Here you would put code that somehow prevents them from doing anything for your HIT, like not loading content etc.
//However, for our purposes here, I just put a simple alert in. Change this to whatever code works for you.
alert("You are not eligible for this HIT because you have already completed an identical HIT.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment