SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru laflair13's Avatar
    Join Date
    Nov 2004
    Location
    TN
    Posts
    610
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?
    Thanks In Advance

    David

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,352
    Mentioned
    179 Post(s)
    Tagged
    9 Thread(s)
    Hi there,

    This will do what you want:

    HTML Code:
    <!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/1...-in-javascript
    Where there is a good discussion of the best way to do this.

    Hope that helps.

  3. #3
    SitePoint Guru laflair13's Avatar
    Join Date
    Nov 2004
    Location
    TN
    Posts
    610
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked perfect.

    Thank You
    Thanks In Advance

    David


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •