Welcome, Guest
Username: Password: Remember me

TOPIC: Generate Random Alpha numeric and store in question

Generate Random Alpha numeric and store in question 9 months 1 week ago #102348

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 204
  • Thank you received: 5
  • Karma: 5
I know this can be done - I just don't know how to do it.

Anyone have a simple implementation for storing and displaying the results of something like this:

Math.random().toString(36).slice(2)

in a question's answer?

As always, any assistance is appreciated.
David
The administrator has disabled public write access.

Generate Random Alpha numeric and store in question 9 months 1 week ago #102352

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 204
  • Thank you received: 5
  • Karma: 5
I'm still at it - no avail! I've tried many snippets like this.

<script>
$(document).ready(
function(){
// Find a random number (here between 1 and 4)
var randNumber = Math.floor(Math.random()*4 + 1);
// Save the number as answer of this question
$('input#answer527453X176X1255').val(randNumber);
});
</script>

Anyone have thoughts on why this doesn't work? the question type is short text.
The administrator has disabled public write access.

Generate Random Alpha numeric and store in question 9 months 1 week ago #102354

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 204
  • Thank you received: 5
  • Karma: 5
Still at it. This is how I spend my Saturdays.

alert('test') works and everything. I'm beggin' here.
The administrator has disabled public write access.

Generate Random Alpha numeric and store in question 9 months 1 week ago #102356

  • dweisser
  • dweisser's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 204
  • Thank you received: 5
  • Karma: 5
So, just in case it helps anyone. This took forever, and it's somewhat of a workaround, but it gave me the desired result. No javascript - all Expression Manager.

I divided:
{floor(rand(100000,999999))} by
{time()} and rounded up to get my random number.

In:
{ceil(time()/floor(rand(1000,9999)))}

Then I used {substr("abcdefghijklmnopqrstuvwxyz", -rand(1,26),1)} to get random alpha characters.

The final implementation, in which I cleverly removed "i", "l" "o", and "O" can be seen here:
{join(ceil(time()/floor(rand(1000,9999))), substr("abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", -rand(1,48),1), substr("abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ", -rand(1,48),1))}

Placing this in the source of your survey item will yield something like this:
231387Cp


Enjoy.
Nebraska David
The administrator has disabled public write access.
The following user(s) said Thank You: Ben_V

Generate Random Alpha numeric and store in question 9 months 1 week ago #102363

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1081
  • Thank you received: 240
  • Karma: 76
thanks for sharing..
=>related previous thread: Generate Unique PIN for user ;)
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 9 months 1 week ago by Ben_V.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.094 seconds
Donation Image