Highlighted

Randomly Assign Field Value?

Avatar

Guest

17-07-2008

Hi I'm wondering if there is away to create a field that will randomly choose 1 of the 3 options in it.



We are having a company BBQ and I was hoping that the PDF could tell the person what to bring since its potluck style. Normally we do printed invites, mix them up (ones saying desserts others saying appetizer etc.) and hand them out.



This is my first time using LifeCycle so any suggestions would be appreciated!



...I should add that I'm using LifeCycle 8...



Thanks,



Jenna

Replies

Highlighted

Avatar

Guest

18-07-2008

Getting it to display a random number was pretty easy acutually but I'm having problems assigning values to the numbers though. I made an array giving the numbers values but as soon as I paste it in, it only picks the last one "an appetizer".



I'm unfortunatly not javascript handy at all. Any help you be greatly appreshated.



This is the little script I've pasted together:



Math.floor(Math.random()*3+1)



meal = new Array(3);

meal[1] = "a dessert";

meal[2] = "a salad";

meal[3] = "an appetizer";
Highlighted

Avatar

Guest

21-07-2008

I was given this script to try out but it doesn't work at all. Am I missing something?



meal = new Array(3);



meal[0] = "a dessert";

meal[1] = "a salad";

meal[2] = "an appetizer";



randnum = Math.floor ( Math.random() * meal.length );



document.write(meal[randnum]);



Thanks for the help!!!!
Highlighted

gkaiseril

21-07-2008

There are many variations of JavaScript and LiveCycle Designer has added other limitations.



For LiveCycle Designer try for the item field's calculation script try:



var randnum = Math.floor ( Math.random() * 3);



if(randum == 0)

$.rawValue = "a dessert";

if(randum == 1)

$.rawValue = "a salad";

if(randum == 2)

$.rawValue = "an appetizer";
Highlighted

Avatar

Guest

21-07-2008

I copied and pasted it in but it didn't work. Is there a certain "Show" I should be using? I have tried it on Enter, Initalize and Calculate.



Thanks for your help!!!!
Highlighted

Avatar

Guest

22-07-2008

Still can't seem to get this thing to work... I can get a random number but I can't get the value assigned to that random number.
Highlighted

Avatar

Guest

22-07-2008

Thanks, I'm not sure why its working now but I got to work:

var randnum = Math.floor(Math.random()*3)



if(randnum == 0)

$.rawValue = "a dessert";

if(randnum == 1)

$.rawValue = "a salad";

if(randnum == 2)

$.rawValue = "an appetizer";



Thanks!