...

View Full Version : Validating and Crediting system



gmichael225
02-22-2007, 09:30 AM
To anyone that will help,
I am trying to setup a page on a Google Pages site (so I cannot put HTML in the HEAD section), that will check a user's answers to questions by using an ID number and a text input. If they get the answer correct, then they get credited one "puzzle point" by increasing the value of a cookie. They can redeem the points for prizes, e.g. one of my fruityloops tracks. I have the page online at http://puzzlepics.googlepages.com/answerchecker,
but It won't work properly. Of course, it won't work in Firefox (apparently) because it uses ActiveX to read the answers (which it checks against the user input) from a .txt file on the server. I am using IE7 to test it.

My code is shown below.

<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
createCookie('puzzlecredit','0','365')
return readCookie('puzzlecredit');
}

function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
<SCRIPT LANGUAGE = JAVASCRIPT>

var countThis, rndNum;

var request = new ActiveXObject('Msxml2.XMLHTTP');
request.open('get', 'answers.txt', true);
request.onreadystatechange = extractURLs;
request.send();

function extractURLs() {
if (request.readyState == 4 && request.status == 200) {
urlArray = request.responseText.split("\n")
start_your_function(urlArray);
}
}
function start_your_function(urls) {
rndNum = 60500 + 70315*Math.random();
countThis = 0;
countThis = parseFloat(countThis);
setInterval("parent.main.location.href = urlArray[countThis]; countThis = countThis + 1;", rndNum);
}

function checkanswers()
{
var searchid = document.answercheckingform.answerid.value
var checktext = document.answercheckingform.answertext.value.toLowerCase()

if(urlArray[searchid])
{
var checkagainst = urlArray[searchid]
if(checktext==checkagainst)
{
alert('Congratulations! You answered this puzzle correctly.')
var existingcredit = readCookie('puzzlecredit');
createCookie('puzzlecredit',existingcredit++,'365')
var newcredit = readCookie('puzzlecredit')
alert('Your credit is now '+)
}
}
else
{
alert('The puzzle ID you entered is invalid. TIP: Remove any 0s before at the beginning of the puzzle ID.')
}
}
</SCRIPT>
<form name="answercheckingform">
<input type="text" id="answerid"> (in numerals please)<br />
<input type="text" id="answertext"><br />
<input type="button" value="Check" onClick="checkanswers();">
</form>

shyam
02-22-2007, 02:57 PM
function checkanswers()
{
var searchid = document.answercheckingform.answerid.value
var checktext = document.answercheckingform.answertext.value.toLowerCase()

if(urlArray[searchid])
{
var checkagainst = urlArray[searchid]
if(checktext==checkagainst)
{
alert('Congratulations! You answered this puzzle correctly.')
var existingcredit = readCookie('puzzlecredit');
createCookie('puzzlecredit',existingcredit++,'365')
var newcredit = readCookie('puzzlecredit')
alert('Your credit is now '+)
}
}
else
{
alert('The puzzle ID you entered is invalid. TIP: Remove any 0s before at the beginning of the puzzle ID.')
}
}



notice that?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum