Read the statement by Michael Teeuw here.
Help choosing more than one item from an array
-
ok, your source ‘lifeFormArray’ is a hash… good for looking up randomly
now to get the user specified list into something usable, split is the way as already posted
// if user specified something if(this.config.lifeForms.length >0 ) { // split will return an array with only one entry if no comma found this.config.user_keys=this.config.lifeForms.split(','); } else // add an entry to a special lifeFormArray entry for missing config info this.config.user_keys.push("none");
now, you want random, or walk the array of user_keys?
function getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } // get one of the user specified data keys, using random var key=this.config.user_keys[this.getRandomInt(this.config.user_keys.length)]; // append that id value to the url. this.url = "http://eol.org/api/pages/1.0.json?batch=false&id=" +this.lifeFormArray.key;
its unclear if u wanted all or just one…
-
-
@justjim1220 make sure to add an entry to the lifeFormArray that matches the string you define for ‘none’ (no user entry supplied)
-
So, would the entry be like this: “Cats”, “Bats”, “Bears”,
or like This: “Cats,Bats,Bears”,
?
-
Well, at the moment it is throwing the following error:
I’ll look at it some more here in a little bit…
Thanks for your input!
-
I am extremely grateful to both of you for your assistance and guidance. I thank you both. :thumbsup:
Jim, as it seems you’ve taken over this topic, I will leave it to you.
-
I don’t know about taking it over, LOL.
Just trying to help! -
@strawberry-3-141 said in Help choosing more than one item from an array:
what you describe above is actually not an array, it’s an object (hash). Arrays are always defined with [] not {}.
Object. Array. What’s the difference? (That’s a joke. Laugh) :-D
-
@justjim1220 that error looks like from the constructed url failing
-
@justjim1220 the second. Don’t depend on users to do multiple entries