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