Hi, I hope someone will notice this. I want to create a random generated number in my form if someone is fill up form, like a ID number, cause I can't edit the default ID database created.
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
Hi! Is there possibility to generate a unique number for wix-form database?
Hi !
Thanks, I've read all the articles, I tried it for myself and it works :
$w.onReady(function () { unixCode(); }); function unixCode (){ var timeStamp = Math.floor(Date.now()/1000); $w('#yourElement').value = timeStamp.toString(); }
Only is there a way to achieve this without having to put an input element on the page ? I would like this to be a 'backend' feature, so no one can see it happening. And hiding it isn't really an option since Goodle doesn't appreciate hidden content.
Thanks !
PS : I saw 2 or 3 different types of code (including yours) what are the differences ?
Hi Tristan,
Here are some threads/info that may help you:
https://www.totallycodable.com/forum/codes-for-templates/unix-time-stamp-code-epoch
https://www.wix.com/code/home/forum/questions-answers/random-number-generator
https://www.wix.com/code/home/forum/questions-answers/solved-i-need-a-help-of-a-wix-expert
Once you create a random number, you can use that for your URL instead of the ID (since the ID cannot be modified in any way).
bump
I'm also interested in changing the default ID which is very unaesthetic.
If anyone has a solution.
My items' URL would be " /{ID}/{Title} "
I'd like the id to be something like "15795169" and the not default Mac-style address.
Thanks !
Thank you Liran! would you please post of a sample code? Thank you again for the help.
Hi geovel,
Before I answer that I have to point out that random numbers are not uniq. Of course, the larger your range is, there's less chance to get duplication. But if you go for it anyway - when generating a new number, don't forget to make sure that you don't already have it as an ID in your database (and if so, generate a new one).
You can use 'Math.random()' to get a random number between 0 to 1 (e.g. 0.7362768324).
Have a look here for ideas on how to get this number to be an integer, and even set a range to that integer.
Also, here's some example on how to generate a UUID string.
Liran.