06-20-2002, 06:00 PM
I am creating a form for someone, and he says he needs a unique number for each submit that he gets...can this be done? Everything is done through JS...I have tried a couple of things, but I can't seem to get it to go...Does anyone have any ideas??
06-20-2002, 06:27 PM
You'll need server-side to do this.
06-20-2002, 07:36 PM
Here's something I was playing around with... since I use random randomness, and intersperse a date stamp as well, the odds against ever getting the same number twice are well... a lot higher than I can count! ;)
I'm sure they are astronomical...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
var mydate = new Date;
var myday = mydate.getDate();
var mymonth = mydate.getMonth()+1;
var myyear = ((mydate.getYear() < 100) ? "19" : "") + mydate.getYear();
var myyear = myyear.substring(2,4);
var myhour = mydate.getHours();
var myminutes = mydate.getMinutes();
var myseconds = mydate.getSeconds();
if(myday < 10) myday = "0" + myday;
if(mymonth < 10) mymonth = "0" + mymonth;
if(myhour < 10) myhour = "0" + myhour;
if(myminutes < 10) myminutes = "0" + myminutes;
if(myseconds < 10) myseconds = "0" + myseconds;
var datearray = new Array(mymonth,myday,myyear,myhour,myminutes,myseconds);
var uniq = "";
var which = Math.round(Math.random()*1);
x = String.fromCharCode(64 + (Math.round(Math.random()*25)+1));
x = String.fromCharCode(47 + (Math.round(Math.random()*9)+1));
uniq += x;
uniq += datearray[i];
Random 24 character string with time factor!
uniq = UniqueString();
06-21-2002, 04:36 PM
I will give this a try...thanks, you're a lifesaver!
11-08-2007, 07:49 PM
11-08-2007, 08:37 PM
For example, a number based on hours - minutes - seconds would have 6 digits (e.g. 113542) but the chance of duplication would be quite high.