Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question My form needs a unique number on each load...can it be done?



    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??
    JamJam

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll need server-side to do this.

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here's an idea for ya...

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

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
    <html>
         <head>
    <script language="JavaScript" type="text/javascript">
    <!--
    function UniqueString(){
         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 = "";
         for(i=0;i<datearray.length;i++){
              for(z=0;z<2;z++){
                   var which = Math.round(Math.random()*1);
                   if(which==0){
                        x = String.fromCharCode(64 + (Math.round(Math.random()*25)+1));
                   }
                   else{
                        x = String.fromCharCode(47 + (Math.round(Math.random()*9)+1));
                   }
                   uniq += x;
              }
              uniq += datearray[i];
         }
    return uniq;
    }
    //-->
    </script>
              <title>
                   Random 24 character string with time factor!
              </title>
         </head>
         <body>
    <script language="JavaScript" type="text/javascript">
    <!--
         uniq = UniqueString();
         document.write(uniq+"<br />");
    // -->
    </script>
         </body>
    </html>
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    New to the CF scene
    Join Date
    Jun 2002
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks...

    I will give this a try...thanks, you're a lifesaver!
    JamJam

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How would i edit this form to generate a shorter unique number. I need a javascript to give a unique number to each person registering on a form of mine. THANKS!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    It is not possible to generate numbers using JavaScript which are in any way sequential. And the shorter the number the greater the probability that a number will be duplicated.

    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.

    You really do need a server-side language to do this. I expect you know that JavaScript has no ability to read from or write to a file (except a cookie).


  •  

    Posting Permissions

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