These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Random Letter & Number Generator

SteeKnow
Registered: Nov 11 2010
Posts: 3

Hello:
 
I'm new to programming (FormCalc & JavaScript) and I'm using Adobe LiveCycle Designer ES 8.2 to create a dynamic form to post online. I need help with creating a "random letter & number generator" in code. The purpose is when someone opens the form online; I will create a unique number/letter combo on the form.
 
Any help or direction would be much appreciated. Thanks!

My Product Information:
LiveCycle Designer, Windows
krm240
Registered: Apr 17 2009
Posts: 95
Try the following:

use a blank form (Javascript)
put a button on it with the following code in the click or up event:

console.clear();
console.show();

// Random Number between 1 and 26
var myRN = Math.random(); // Seed
console.println("Random Seed is: " + myRN); // object for debugging

var lowerBoundary = 1;
var upperBoundary = 26;
console.println("Random # is: " + Number(Math.floor(myRN*(upperBoundary - lowerBoundary))+ lowerBoundary ));

// Random uppercase Letter
var lowerBoundary = 65;
var upperBoundary = 90;
console.println("Random UpperCase Letter is: " + String.fromCharCode(Math.floor(myRN*(upperBoundary - lowerBoundary))+ lowerBoundary));

// Random Lowercase Letter
var lowerBoundary = 97;
var upperBoundary = 122;
console.println("Random LowerCase Letter is: " + String.fromCharCode(Math.floor(myRN*(upperBoundary - lowerBoundary))+ lowerBoundary));

SteeKnow
Registered: Nov 11 2010
Posts: 3
krm240,

Thanks for helping, the code works perfect. How would I revise the code to work in a text box and have it initialize when the form is opened. Please let me know if this is possible. Thanks!

Regards,

SteeKnow
krm240
Registered: Apr 17 2009
Posts: 95
Put a text box on the form
Put the code I provided in the initialize event of the form

Change the code
from
console.println("Random UpperCase Letter is: " + String.fromCharCode(Math.floor(myRN*(upperBoundary - lowerBoundary))+ lowerBoundary));

to
textbox.rawValue = String.fromCharCode(Math.floor(myRN*(upperBoundary - lowerBoundary))+ lowerBoundary));


SteeKnow
Registered: Nov 11 2010
Posts: 3
krm240, I really appreciate the help. Thanks!

Best regards,

SteeKnow