-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by Maiskolben
-
-
Hello Folks,
I just wondering why JS cannot handle associative arrays like php does. Ok, after a while of investigation I stuck with a little code now. Once I've written a simple q&a spamcheck for my contact form in php, hence, I try to adapt it to a js contact form: It's a beautiful pop-up form that costs me 7 dollars, I was just missing that in this script I bought one week ago comes with NO spamcheck functionality, so I would like to build it on my own, maybe with your help?
I know that there are no associative arrays in js. My basement is this code:
var questions = { 'The color of the sky?': 'blue', 'Abraham...': 'lincoln', '10 minus 2, plus 3..': '11', 'Rupert the rednose...': 'reindeer' };
So, next I just need to count the "keys" or array-entries, object parameters, you name it.
Finally I want to shuffle the indexies and return one single question.
To count the "array" I tried this:
var count = 0; // initializefor (var i in questions) { if (questions.hasOwnProperty(i)) { ++count; } }var min = 0; var max = count;alert(count);
...and it works like a charm! My problem is now the indexies e.g. the KEYS of this Object... I don't know how can I shuffle them, and even put out then. Any suggestions to this?
Maybe something in this direction:
var qsingle = shuffle(min, max);alert(qsingle);
But the output is nothing, the script even breaks... But works fine in php! Any help would be greatly appreciated!
associative array?
in JavaScript
Posted · Edited by Maiskolben
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!):
next I get the anwser in an hidden field of my formular, base64 decoded:
And finally I check, if the typed answer matches the right answer, all lowercase:
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!