Hey guys,
thank you for your response! After a while of try & error and your help, I just have my spamcheck running!
I've found this and use it to shuffle my array (thank you JSG!):
function shuffle(array) { var m = array.length, t, i; while (m) { // Pick a remaining element… i = Math.floor(Math.random() * m--); // And swap it with the current element. t = array[m]; array[m] = array[i]; array[i] = t; } return array;} var spamcheck = [ {f: 'Question A', a: 'ANSWER A'}, {f: 'Question B', a: 'ANSWER B'}, {f: 'Question C', a: 'ANSWER C'} ]; shuffle(spamcheck);
next I get the anwser in an hidden field of my formular, base64 decoded:
<input class="kissmebaby" name="chk-hidden" id="chk-hidden" type="hidden" value="'+Base64.encode(spamcheck[1].a)+'" />
And finally I check, if the typed answer matches the right answer, all lowercase:
var rightanswer = document.getElementById("chk-hidden").value;var x = document.getElementById("answerfield").value;var givenanswer = Base64.encode(x.toLowerCase()); // note, BASE64.encode (references to a function)if (givenanswer !== rightanswer) { document.getElementById('answerfield').style.background = "#f9ef9e"; // tell the user there is something wrong... } else { //go to the serverside php-script viá ajax}
and this is it. Thanks for putting me on the right way!
PS: this works for me like a charm, may it be there is something "too much" in this shuffle-function, but I'm glad it works now and wouldn't change anything, the performance(s) of the entire script(s) on my website is ok..
PPS: @davej: thank you too, I gladly abandoned the idea to solve this viá the indexies!