Results 1 to 3 of 3

Thread: Generate auto number

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generate auto number

    i want to know if java script can generate auto number like 0001..in my project (payment system) i need to do resit number and print the detail about the payment..need some idea...tq

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Javascript can generate any random number, try searching google for Math.random().
    Jeremy | jfein.net

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Normally a receipt number will be a sequential number rather than a random number as you've suggested, if you look at any payment system. To generate a random number in JavaScript you can make use of

    Code:
    Math.random();
    but if you use it alone the number it generate may not be a usable one for you. So normally when users generate a random number they mention the range in which the newly generated random number should fall it. Like the following manner:

    Code:
    var rand = Math.floor(Math.random() * 101);
    The above code will generate a number between 0 and 100. But if you want to make the first number 1 and second number 2 this will not work correctly as we can't control the way it generates the actual number. More if you are expecting a number like 00001 for your purpose you have to treat it as String not a number as a number 00001 is equal to 1 in JavaScript.

    I would suggest to use server-side methods for storing the receipt number if you want to use it in a more efficient manner.

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
  •