By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Random Reference Number

Jacotheron
P: 44
I want to create a javascript that is able to randomly generate a 7 digit number and fill it in a textbox that is unchangeable. It should not repeat the same number before all of the possible numbers has already been used.

Can someone please help??
Jan 14 '08 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
Unless you store all previous numbers, this won't be possible.

Use Math.random() for the randomization. Note that it gives a number between 0 and 1. To get a useful number between 1 and something, use something like Math.floor(Math.random()*maxNum+1).
Jan 15 '08 #2

Jacotheron
P: 44
Unless you store all previous numbers, this won't be possible.

Use Math.random() for the randomization. Note that it gives a number between 0 and 1. To get a useful number between 1 and something, use something like Math.floor(Math.random()*maxNum+1).
How would I store the previous numbers that it can't be used again in the next 30 days. With the "Math.floor(Math.random()*maxNum+1)" I supose I can get it right.

Thank you for your help
Jan 15 '08 #3

gits
Expert Mod 5K+
P: 5,329
hi ...

in case you store it in a database you could retrieve all the used numbers on pageload and build a lookup list with it ... another way would be a cookie at the clientside ... but i would prefer the db-way :)

kind regards
Jan 15 '08 #4

Jacotheron
P: 44
hi ...

in case you store it in a database you could retrieve all the used numbers on pageload and build a lookup list with it ... another way would be a cookie at the clientside ... but i would prefer the db-way :)

kind regards
How do I create a database that the client browser can add the number automaticly. (I have very little experience in javascript as you might have noticed).

Thanx for the help
Jan 16 '08 #5

acoder
Expert Mod 15k+
P: 16,027
How do I create a database that the client browser can add the number automaticly.
A database would require server-side coding. Which language are you using on the server-side?
Jan 16 '08 #6

Jacotheron
P: 44
A database would require server-side coding. Which language are you using on the server-side?
I can't yet use any serverside code, but would try to do something about that (I am the same person of the "Bookings manager" and this client have selected the Micro option too, like every body else).

I should have a reply about tomorrow (18 January 2008) about server side code.
Jan 17 '08 #7

acoder
Expert Mod 15k+
P: 16,027
I can't yet use any serverside code, but would try to do something about that (I am the same person of the "Bookings manager" and this client have selected the Micro option too, like every body else).
Yes, I noticed. You'll have to try to convince them. If they don't agree, you can use cookies, but that would only be random for that one person (not across al people using the system) and I think cookies have a size limit.
Jan 18 '08 #8

Jacotheron
P: 44
Yes, I noticed. You'll have to try to convince them. If they don't agree, you can use cookies, but that would only be random for that one person (not across al people using the system) and I think cookies have a size limit.
Well, thanx for the help, even as I was not successful with this.
Jan 18 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Well, thanx for the help, even as I was not successful with this.
You weren't successful in convincing them that they needed server-side code? Sometimes clients need to know that things are simply not possible the way they see it. This can only be done on the server-side. JavaScript is great at what it does, but it's limited (for a reason).
Jan 18 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.