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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Validating and Crediting system

    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>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by gmichael225 View Post
    Code:
    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?


  •  

    Posting Permissions

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