[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4999
  • Last Modified:

Generate random 6-digit alpha-numeric code.

I need a javascript that will be envoked via an onclick

I need a random 6-Digit alpha-numeric (uppercase) id created when the user clicks the link provided. The id would then populate a form field.

So basically the user click the link and the form field gets populated with the 6-digit id.

Thanks,
Curtis
0
rcmb
Asked:
rcmb
1 Solution
 
MrRobotCommented:
0
 
hieloCommented:
add upper case characters if you want them as well
<script type="text/javascript"><!--
function getID(idLength)
{
      var chars="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
      chars=chars.split(",");
      var min=0;
      var max=chars.length-1;
      var id="";
      for(var i=0; i<idLength;i++)
      {
            id+=chars[ Math.floor(Math.random()*(max - min + 1) + min) ];
      }
return id;
}
alert(getID(6));
//--></script>
0
 
rcmbAuthor Commented:
Both worked equally as well but MrRobot was first. Thanks for your help and quick turnaround.

Curtis
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now