Getting a random ID put on a page

Hey all,

I am wanting something to generate a unique 5 digit ID, like Ah45P or something along those line.

Heres my set up, someone comes to the site, fills out a form, they go to a thank you page, then they see “click to get your Unique ID”, upon click they go to another page that says… “Your Unique ID is 12345” . (hope that made sense)

Is there any tutorials that I can do that with?

Hi there,

This will do what you want:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Generate unique ID</title>
  </head>

  <body>
    <p>Your unique ID is: <span id="uniqueID"></span></p>

    <script>
      function makeid(){
        var text = "";
        var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        for( var i=0; i < 5; i++ ){
          text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
      }

      document.getElementById("uniqueID").innerHTML = makeid();
    </script>
  </body>
</html>

I’m afraid I can’t take credit for it though, it’s lifted straight from Stack Overflow: http://stackoverflow.com/questions/1349404/generate-a-string-of-5-random-characters-in-javascript
Where there is a good discussion of the best way to do this.

Hope that helps.

Worked perfect.

Thank You