If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Multiple javascript generators on one page?

Let me precede my question by stating that I'm a pretty helpless newbie when it comes to coding. I'm attempting to teach myself, but progress is slow going. Sorry about that!

I made a couple of random name generators in java script a couple of months ago. They're currently on separate pages, but I'd like to combine them to a single page, and then have users toggle between the generators by using radio buttons. My first question: Is that possible? Which is closely followed by: How would I do that, assuming it can be done?

Basically, the code pulls words from the variable sets and smashes them together to create a name that has three parts. (They're names for a fantasy game, if anyone's curious.) The other generators I have use this same code, but have different words in the variable sets; for example, one is water-themed, another is darkness-themed. Like I said above, I'd like there to be buttons there for the user to click, selecting one generator over another.

Thanks for any help! And if anything doesn't make sense, I'll happily clarify.

If you pass the wordlists into the generator then you can have one function that can be used for all of the generators. The only other variables are the two ids so pass those to the function as well.

Also you seem to be incorrectly using parseInt where you ought to be using Math.floor - parseInt converts numbers from base 2 through base 36 to base 10 while Math.floor rounds the number down to the nearest integer.

Thank you so much for getting back to me and for your help! I've changed the parseInt(Math.random() to Math.floor(Math.random() - Thanks for correcting that.

I really appreciate your code example, but I'm still not entirely sure I understand. So I can add all my other wordlists, just give them new names (like wordlist7, wordlist8, etc), and then change the actual code of generating the name to reflect these changes. Which would mean the new code looks like this:

And then basically repeat that until all my wordlists are accounted for? I tested that at JSFiddle and didn't get a result, so I know I've messed up somewhere.

And regarding the radio buttons - How do I attribute a radio-button choice to a certain generator?

I apologize again for the convoluted nature of this issue. I think I have the sort of questions that are better asked verbally with someone in the same room rather than done part by part over a forum, but I don't know anyone who can code javascript.

Thank you again for your help! I really, really, really appreciate it!