Name generator script

I have made a  complete name generator script to download and use as your own. The script contains a full functional HTML page with all necessary JavaScript code, HTML and CSS, and can be run in any browser.

The name generator script is a complete do-it-yourself name generator! Ready to run with or without changes. The script is a simplified version one of the one I use at all my name generators.

The script is thoroughly explained and commented in the download file. So it is very easy  to work with for everybody, even for beginners to web programming. If you like further explanation on how the script works visit my How to make a name generator tutorial, where i you through a only slightly more simple generator script.

To get up and running just download the script, change the text and change the word arrays to your likings.  And you got yourself your own personal name generator.

How to use the name generator script

Getting started

Download the name-generator-script.zip.

Or just visit the name generator script demo, right click the page. Select view source. Copy the source to a text-editor.
Save is at generator.html.

How to run it

It’s easy. Just open the html file with your favorite browser.

How to edit it

To edit this page open it with a text editor with syntax highlighting. I’ll strongly recommend notepadd++ a free, fast and flexible text editor, I also use myself.

Name Generator FAQ

No one yet. Guess the code must be  self-explanatory. ;)  Well seriously… if you need help just ask your questions below. I’ll try my best to help you.

EDIT: Well now the comments works as a FAQ.  Please check them to see if you question already has been asked.

How to get visitors on your new name generator

If you make a cool name generator, I might wanna make a review of it. Just write a comment and I’ll look into it.

How to host your new name generator

There’s several ways to host your new name generator.

If you want your own domain name there’s a lot of companies to choose from. If you stick to some of the bigger companies the hosting is often very reliable.

The price level is often low and sometimes you can get a free domain name with the hosting plan.

But you can also find free hosting, if you don’t want your own domain.  Just make sure the service you choose supports the running of JavaScript.

This entry was posted in Name generator stuff and tagged , , . Bookmark the permalink.

45 Responses to Name generator script

  1. Pingback: How to make a name generator « Name Generators Blog

  2. Pingback: Roll your own | Danish webdesign - Copenhagen based freelance webdesigner Thomas Fals

  3. Pingback: Name generator widget « Name Generators Blog

  4. Pingback: Navnegenerator | Blog om webudvikling

  5. Pingback: Name Generators Blog » Name randomizer

  6. Pingback: Blog name generator | Name Generators Blog

  7. Pingback: navnegenerator « Webdesign

  8. George says:

    Cool name generator script, mate. Exactly what I was looking for. Thanks.

  9. nicole says:

    This is great. Is there a way this can be modified to add on a input box so that it can give different types of names for say, males or females?

  10. Niels says:

    @nicole

    Yes of course. But do you mean a checkbox or maybe a radio buttun, so the user have to choose if he wants the generator to make a male or a female name?

  11. nicole says:

    Well first i need a select box to find out their gender, but i also need a text input box to collect their name cause i want to output fantasy names that are similar to their own name.

  12. Niels says:

    Well sorry if I make the wrong assumptions here, but when you ask I assume, that you are not too familiar with JavaScript.

    I think it will be hard to find a functional name generator script, that does exactly what you want, so you probably need to tweak anything you might find.

    But here’s a few tips:

    One easy way of solving the first issue, choosing sex, in a simple way is to duplicate the function in the generator script. Name the first function generator_male() and the other generator_female(). Make 2 buttons. One for male names and one for female names each of them calling the corresponding generator function.

    The other part is a little more tricky, if you new to programming. Getting the name from a input filed is easy enough though:

    document.getElementById("myInputfieldId").value

    It’s generating names that are similar to that name that’s a tad tricky. If you wanna use a traditional name generator script, you need to write a pattern/algorithm that’s exact describe what similarities you are testing for.

    As an alternative you can Change letters to make fantasy names. In this example I only change the vowels. But from the example it’s pretty easy to add new rules. For example change the first consonant, the last consonant and so on.

    Good luck. :)

  13. nicole says:

    Thankyou Niels. Well I found this script for a name generator and began trying to tweak it to my liking as you suggested. Anyhow to make a long story short it is not working now. The original code worked but it only had three categories of names, male names, female names and last names. I then added in some new arrays and some new selection boxes on the form, which is when I think I fudged it. The code is below. Not sure what I did wrong.

    var maleclone = new Array(
    “charlie”,”curly”,”cole”,
    )

    var femaleclone = new Array(
    “tanja”,”bella”,”morgan”
    )

    var malebothan = new Array(
    “teel”,”Ung”,”Jaster”
    )

    var femalebothan = new Array(
    “Traest”,”laryn”,”shila”
    )

    var bothanlastname = new Array(
    “fey’lya”,”sel’ab”,”saav’etu”
    )

    var clonelastname = new Array(
    “101”,”102″,”103″
    )
    var r = 0;
    var i = 0;

    function RandomName(nameform) {
    r = Math.floor(Math.random() * lastname.length);

    if((nameform.species.options[1].selected == true) && (nameform.gender.options[1].selected == true))
    {i = Math.floor(Math.random() * femalebothan.length);
    nameform.first.value=femalebothan[i]
    nameform.last.value=bothanlastname[r]
    }

    else if((nameform.species.options[1].selected == true) && (nameform.gender.options[2].selected == true))
    {i = Math.floor(Math.random() * malebothan.length);
    nameform.first.value=malebothan[i]
    nameform.last.value=bothanlastname[r]
    }

    else if((nameform.species.options[2].selected == true) && (nameform.gender.options[1].selected == true))
    {i = Math.floor(Math.random() * femaleclone.length);
    nameform.first.value=femaleclone[i]
    nameform.last.value=clonelastname[r]
    }

    else if((nameform.species.options[2].selected == true) && (nameform.gender.options[2].selected == true))
    {i = Math.floor(Math.random() * maleclone.length);
    nameform.first.value=maleclone[i]
    nameform.last.value=clonelastname[r]
    }
    }
    // End –>

  14. Niels says:

    Well, I can’t see any obvious mistakes in the code without actually running it, and I’m sorry but I really haven’t got the time to do that that, so you have to debug it yourself.

    Debugging is always hard work, but the harder the work the more rewarding it will also be when you get the code to work.

    Here’s a few basic tips to how to debug more efficiently.

    First of all use Firefox with a Firebug installed. It gives very valuable error messages.

    Then start all over with the basic name generator script that worked. And this time around add only one new feature at the time. If the new feature doesn’t work, use a lot of alert()’s placed all over the generator script. Alert all your variables to check, if they hold the values you expected. Alert lots of “test1″, “test2″, “test3″ to check how long you get in the code before it all crash, and to check if your conditional statements works as you expect.

    When one feature is working add the next one and so on.

    Good luck. :)

  15. Jessica says:

    Wait do we have to make it ourself? Or did you already make one that we can use instead of making one ourselves…

  16. Niels says:

    Hi Jessica. :)

    I already made a complete name generator script ready for download. But the name arrays are very short, so you have to replace my names with your own names in these arrays. It’s a bit like those cakes where you just need to add some water and then bake them yourself. ;)

    And just like the cakes, it’s actually pretty easy to do. Even if it’s the first time you try to program. Just download the generator script, and read this post and the “how to make a name generator”-post carefully. Everything you need to know is there.

    If you don’t wanna do anything yourself, but just want some cool names now just visit the name generators.

  17. Dino Dogan says:

    Hey Niels, I was wondering if this script can be integrated easily (or with great difficulty) into a php/mysql platform to randomly generate names for users who create an account.

    So for example, for every user that joins, I want to automatically create 3 guild names that are unique.

    Any insight is greatly appreciated :-)

  18. Niels says:

    Hi Dino.

    Interesting idea. If it’s easy or difficult… well it solely depend of your programming skills. ;)

    If I should make such a feature, I would transfer the name generator to php. It shouldn’t take more than 30 minutes. All the hard work lays in building the word arrays, the generator itself is very simple.

    The benefit of making it in php is that all you other functionality around the login and connections to the mySQL database is run in php scripts. It’s much easier to deal with database and the php, when all the funtionality lays on the server, instead of when the name generation takes place in the browser.

    I would do something like this:
    *When the users log ins for the first time, you run the name generator script
    *Compare the results with the guild names already in the MySQL database
    *Repeat name generation if necessary
    *Finally save the new and unique guild names in the database.

    It does take some work though to build such a flow. For the skilled programmer it’s probably pretty easy, for me it would take a little more time.

    Good luck, and when you get it up please come back and share. :)

  19. Dino Dogan says:

    @Niels
    Hi Niels, I really appreciate the time you’ve taken to answer this. I have none of the skills you refer to but I have a coding genius @dancristo next to me, so Im sure he can figure it out :-)

  20. Human says:

    As you can see from my “name” I can’t think of names very easily… I’m also a little slow on this, so I’m can’t get all this to work

  21. Ton says:

    How do you remove duplicate words from occurring? For example, if I had the same words in wordlist1 and wordlist2, it’s possible that the words can be paired together. How can I prevent this from happening?

  22. Niels says:

    Hi Ton

    Sorry for the delayed reply, but I have been away on winter vacation.

    You can do it avoid that the name generator script makes duplicate names if you insert this this simple while loop in the script:

    ...
    var randomNumber1 = parseInt(Math.random() * wordlist1.length);
    var randomNumber2 = parseInt(Math.random() * wordlist2.length);
    while(wordlist1[randomNumber1] == wordlist2[randomNumber2]){
    	randomNumber2 = parseInt(Math.random() * wordlist2.length);
    }
    var name = wordlist1[randomNumber1] + " " + wordlist2[randomNumber2];
    ...
    

    The loop tests if the names are duplicate. As long as they are, a new random number will be generated for the second name.

  23. Ashley says:

    I want to use this on Blogger…how do you do that. Thanks for the script! I has really helped a novice like me!

  24. Ashley says:

    It’s me again! Sorry!
    I am wanting to create separate name generators for women and men. When I put both on the page only one will work and it mixes the two generators (for example Celia (woman) Rock (male). Is there any way to stop this from happening? I’ve tried putting them in separate posts but, I am still having the same problem. I am sure it is a matter of changing some things around but I am at a loss! As of right now I just posted the women’s generator until I can figure out the men’s generator.

  25. Niels says:

    Should be quite simple, Ashley. Just a conflict in the naming. We just need some re-naming.

    Keep the female name generator as it is. And change the function name for the male generator. Like this

    function generator(){…

    to

    function male_generator(){…

    And on the button:

    <input type=”button” value=”Make name” onclick=”generator()” />

    to

    <input type=”button” value=”Make name” onclick=”male_generator()” />

    And if you also execute the script on load remember to change the body tag to this:

    <body onload=”generator();male_generator”/>

  26. Ashley says:

    Hey, I’m not seeing what you said I should change the body tag to. By the way, thanks for you help! You rock!

    • Ashley says:

      I’m still having trouble. With the name change for the males: I am able to click the button at the top under the females and get a female first/last name but, if I click the male button it displays above the female button. Any suggestions?

      • Niels says:

        Yes more name confusion. Each name script manipulates the same elements in the HTML.

        Try to change this in the second script:

        //If there's already a name it is removed
        if(document.getElementById("male_result")){
        document.getElementById("male_placeholder").removeChild(document.getElementById("male_result"));
        }
        var element = document.createElement("div");
        element.setAttribute("id", "male_result");
        element.appendChild(document.createTextNode(name));
        document.getElementById("male_placeholder").appendChild(element); 
        

        I have changed all the “placeholder” and “result” to “male_placeholder” and “male_result”

        And in the HTML you need to make a new div with the id male_placeholder. Like this:

        <div id="male_placeholder">
        

        Hope it’ll do the trick this time. ;)

    • Niels says:

      Sorry I missed the body-tag. Here it is:

      <body onload=”generator();male_generator()” >

  27. Its me says:

    Hmm.. so is it possible to assign the name based on a text input? Not just random. Thats what I’ve been looking for everywhere with no luck. Same as gangstaname.com but with changable output names. Wish I could find a script to do this.

    • Niels says:

      Hey you. :)

      Yes. You can do that. And you can combine it with the randomness too.

      Basically you need to need to get the string from the input field and then do some string manipulation to process it.
      Then you can make conditions based on the name or the different characters in the string.

      For example if the name starts with “a” use array #1, “b” use array #2. If the second letter is “c” use array #3 etc. You can add different kinds of complexity to the name generation.

      Another example could be that you use the first vowel in the name and replace the first vowels in the random generated name with this vowel.

      It is in fact pretty easy to do, if you got the basic understanding of scripting. But it’s probably hard to find a finished script that will do exactly what you are after.

      I don’t use input fields myself on my name generators, because I want the generators to be as easy to use as possible. Some users request the possibility but th majority just prefer to click one more time.

      Personally I think the gangsta name generator is a pain to use, because you need new text inputs every time you want a new name. And further more there is no obvious connection between my input and the generated name, and in that case it just seems plain stupid with all the extra waiting and typing.

      • Its me says:

        Thanks for the quick reply!

        I’ll give reason for wanting this.

        http://www.youtube.com/watch?v=MlqA4q75LOQ

        So in the movie two guns become 1 by a simple averaging equation, but a name has to be generated for this gun. So the same input always has to produce the same output, no randomness. So in this case the “gangsta name generator” would be suitable, though as you say theres no obvious connection between input and output and I assume to create a connection the code would be many times more complex (though desirable, not really required in this case).

        So I was thinking there’d be a few names and an arbitarily named code to avoid same names “A21 face popper” for example :P

        Just looking around to have a play, nothing serious :P

        • Niels says:

          Ahh. I see. An interesting challenge.

          Wouldn’t it be preferable if the new gun name was some way corresponding to the “parent” guns. Then the name would reveal some of the initial properties of the gun. And it would also give the name some sort of brand. A history and some reliability”.

          You could made rules in scripting to do the trick. For example:

          If you got the “A21 Automatic” and the “Xtreme Facepopper” you could split on the space and make the new combinations:
          “A21 Facepopper” , “A21 Xtreme” , “Automatic Facepopper”, “Automatic Xtreme”.

          And the other way around.

          ” Facepopper A21″ , “Xtreme A21 ” , “Facepopper Automatic “, “Xtreme Automatic “.

          With rules for witch name to use fist and witch last, you would end with identical outputs for each identical input. And it would be easy to make exceptions. Say every 10 times you choose one of the 7 other name combination instead. Just to spice things up a little. ;)

          Would still give some challenges, but it would be a very fast way to start out?

  28. Dave says:

    Hello there

    Just want to make a nick name for a chat app, so no one can fake me plz help me with this

  29. Logan says:

    Thanks, this is just what needed to get started, but I would like to make something a little more complicated, like a full character generator (name,age,height,weight,eye color, hair color) Would I be able to edit this code to do that? (or something like it?)

  30. Niels says:

    Hi Logan.

    It’s very easy to transform this name gen script to something more complex. You just keep adding small generators for each new function you want. It’s the same whether you want to generate an name, a eye color, hair color. Just swap the name arrays with new arrays containing the colors etc.

    Make the number generators are even easier as you just want to show the generated numbers, and not the corresponding names. You might need to check a tutorial on making random numbers to make the exact random numbers you want. Like weight between 60 and 100kg etc. Very easy and also fun to do.

  31. Ebony says:

    Hello! I was using this as a website name generator, and it was working perfectly before. However, it suddenly seems to refuse to spit out a name no matter how many times I click the button. Do you have any idea why this may be?

    • Niels says:

      Hi Ebony.

      Sorry to hear. If you didn’t touch anything maybe you web hotel made a change. Are you using any kind of blogging or cms platform where the JavaScript might get stripped?

  32. Frank says:

    Cool script. I want to add it to my kins website. I only know a little HTML & CSS. I want to have Dwarf, Elf, Hobbit and Human names. Any ideas how I can have it change? Maybe with a drop down?

  33. Karen says:

    Hi Niels,

    How do you add a third variable? I can’t seem to figure it out.

    Thanks!

  34. Remco says:

    Hi Niels,
    I am trying to run your fantastic script on a wordpress blog (http://www.hondentraining.nu/wp/hondennamen.html). I can’t get the script to work properly. I am not sure whether it has to do with the code.
    However, when I put the in the header.php the names still don’t refresh when pushing the submit button. They only refresh, when I do a full page refresh.

    This is my code:

    function generator(){

    var wordlist1 = [“A”,”Ad”,”Ai”,”Al”,”Am”,”An”,”Ar”,”As”,”Ba”,”Bal”,”Ban”,”Bar”,”Bas”,”Be”,”Ben”,”Bi”,”Bik”,”Bin”,”Bo”,”Boy”,”Bre”,”Bru”,”Bul”,”Ca”,”Car”,”Cas”,”Ce”,”Chi”,”Cli”,”Co”,”Cor”,”Da”,”Dai”,”Dan”,”Dar”,”De”,”Dex”,”Die”,”Dil”,”Din”,”Dja”,”Djoe”,”Do”,”Doe”,”Du”,”Dum”,”E”,”Ed”,”El”,”Em”,”En”,”Ep”,”Fa”,”Fan”,”Fe”,”Fi”,”Fla”,”Flu”,”Fon”,”Fre”,”Fro”,”Ga”,”Gan”,”Ger”,”Gi”,”Gon”,”Gor”,”Gus”,”Hap”,”Hun”,”I”,”Ja”,”Jim”,”Jo”,”Jor”,”Ka”,”Kar”,”Kaz”,”Ke”,”Kil”,”Kit”,”Knu”,”Ko”,”Kwi”,”La”,”Las”,”Le”,”Lex”,”Lo”,”Lob”,”Lor”,”Lu”,”Ly”,”Ma”,”Mal”,”Mar”,”Mas”,”Max”,”May”,”Mer”,”Met”,”Mi”,”Muf”,”My”,”Na”,”Ne”,”Nel”,”Nik”,”No”,”O”,”Oli”,”Os”,”Pa”,”Pal”,”Pep”,”Pi”,”Pin”,”Pu”,”Puk”,”Qui”,”Ra”,”Rai”,”Ral”,”Ram”,”Ren”,”Ri”,”Ro”,”Rox”,”Ru”,”Sa”,”Sam”,”San”,”Scoo”,”Sen”,”Sep”,”Sha”,”Sja”,”Sloe”,”So”,”Spo”,”Sta”,”Sul”,”Ta”,”Tar”,”Ter”,”Ti”,”Tim”,”Wo”,”Xa”,”Xan”,”Xe”,”Xy”,”Ya”,”Yen”,”Yoe”,”Va”,”Zap”,”Zar”,”Zev”,”Zi”,”Zim”,”Zip”,”Zo”,”Zor”];

    var wordlist2 = [“ac”,”ak”,”as”,”bas”,”be”,”ber”,”bes”,”bo”,”bon”,”by”,”ca”,”cer”,”co”,”cu”,”dee”,”der”,”dit”,”do”,”dor”,”dy”,”el”,”er”,”fel”,”fer”,”gel”,”gos”,”gus”,”gy”,”ing”,”ix”,”jer”,”kel”,”kie”,”ko”,”ky”,”la”,”las”,”li”,”lie”,”lo”,”ma”,”mo”,”my”,”na”,”nis”,”no”,”ol”,”on”,”on”,”per”,”pie”,”rah”,”ras”,”sar”,”sha”,”sor”,”stel”,”ster”,”sty”,”ta”,”tah”,”tan”,”tan”,”tas”,”tie”,”tis”,”ton”,”tor”,”ty”,”vis”,”win”,”yo”,”zer”,”zo”,”zy”]

    var randomNumber1 = parseInt(Math.random() * wordlist1.length);
    var randomNumber2 = parseInt(Math.random() * wordlist2.length);
    var name = wordlist1[randomNumber1] + “” + wordlist2[randomNumber2];

    if(document.getElementById(“result”)){
    document.getElementById(“placeholder”).removeChild(document.getElementById(“result”));
    }

    var element = document.createElement(“div”);
    element.setAttribute(“id”, “result”);
    element.appendChild(document.createTextNode(name));
    document.getElementById(“placeholder”).appendChild(element);
    }

    body{font-family: arial, serif;}
    #generator{background:#e9f3f6;border:1px solid #cccccc;margin:30px 0;font-size:28px;font-weight:bold;padding:50px 0 20px;text-align:center;-moz-border-radius: 5px;-webkit-border-radius: 5px;}
    #generator input{font-size:16px;font-weight:normal;margin-top: 30px}
    #footer{font-size: 10px; color: #999; margin: 30px 0 0 0;}
    #footer a{color:#999}

    Generator is gemaakt met de hulp van online name generators.

    • Niels says:

      Hi Remco

      Sorry for the belated reply, but I have been away on a autumn vacation. :)

      It sounds like it could be a WordPress problem with the onclick events being not allowed. If you can upload the script to the link again, I’ll take a look at it with my firebug.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>