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.
Bookmarks