Skip to main content
Participant
July 8, 2022
Question

Quote ID Generator Button

  • July 8, 2022
  • 1 reply
  • 830 views

I am createting a pdf form that has a unique field and button. The field is called "ID" the button is called "Generate Quote #"

 

That i have managed so far is that pressing the button will generate a random number in the ID field, however, i have noticed when testing that the # is not always the same length digit wise. I would like it to always be 13 digits. Therefor I want to add a way to add extra 0's at the end of the number string so it will always be 13 digits. I dont know if i should add this to the button, or ID field propoerties under Calculate so it takes the number generated and clacualtes it to be 13 digits. ive tried a few methods but they all seem to breeak the number generation.

Here is the Action on Mouse up javascript for the button; 

 

this.getField("ID").value = (Math.floor(Math.random()* Math.pow(10,13)));

 

if (this.getField("ID").value == "") this.getField("ID").value = (Math.floor(Math.random()*Math.pow(10,13)));

 

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
July 8, 2022

Here's an alternative way of doing that:

 

var randomNumber = "";
while (randomNumber.length!=13) randomNumber = Math.random().toString().replace(/\D/, "").substr(-13);

Participant
July 11, 2022

I get a syntax error and im not sure why

try67
Community Expert
Community Expert
July 11, 2022

Post your code.