Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Generate Random Alpha numeric and store in question

Generate Random Alpha numeric and store in question 10 Monate 2 Wochen her #102348

  • dweisser
  • dweissers Avatar
  • OFFLINE
  • Bronze Donor
  • Beiträge: 205
  • Dank erhalten: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Generate Random Alpha numeric and store in question 10 Monate 2 Wochen her #102352

  • dweisser
  • dweissers Avatar
  • OFFLINE
  • Bronze Donor
  • Beiträge: 205
  • Dank erhalten: 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Generate Random Alpha numeric and store in question 10 Monate 2 Wochen her #102354

  • dweisser
  • dweissers Avatar
  • OFFLINE
  • Bronze Donor
  • Beiträge: 205
  • Dank erhalten: 5
  • Karma: 5
Still at it. This is how I spend my Saturdays.

alert('test') works and everything. I'm beggin' here.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Generate Random Alpha numeric and store in question 10 Monate 2 Wochen her #102356

  • dweisser
  • dweissers Avatar
  • OFFLINE
  • Bronze Donor
  • Beiträge: 205
  • Dank erhalten: 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
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: Ben_V

Generate Random Alpha numeric and store in question 10 Monate 2 Wochen her #102363

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1122
  • Dank erhalten: 255
  • Karma: 79
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...
Letzte Änderung: 10 Monate 2 Wochen her von Ben_V.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.120 Sekunden
Donation Image