Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Randomly Assign Field Value?

Not applicable
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
8 Replies
gkaiseril
Level 7
Level 7
Use JavaScript's Math.random() function to get a random number between 0 and 1.
Not applicable
Thank you!

I'm not sure how to do that but I will try to figure it out!



Thanks again!
Not applicable
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";
Not applicable
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!!!!
gkaiseril
Level 7
Level 7
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";
Not applicable
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!!!!
Not applicable
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.
Not applicable
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!